C# 开发经验
C#泛型作为返回类型的写法
public static T GetObj<T>(Employee model)
{
T result = default(T);
if (model is T)
{
result = (T)(object)model; //或 (T)((object)model);
}
return result;
}
控件在设计模式时,禁止访问数据库和API
private async void SetMoldStandardResourceControl_Load(object sender, EventArgs e)
{
if (this.DesignMode == false)
{//控件在非设计模式下才访问数据库
await SetDataSource();
m_ProjectCategories = await m_ProjectCategoryService.GetAllAsync();
}
}
27.监控性能需引用 System.Diagnostics
Stopwatch stopwatch = new Stopwatch();
stopwatch.Start(); // 开始监视代码运行时间
//.........代码..................//
stopwatch.Stop(); // 停止监视
TimeSpan timespan = stopwatch.Elapsed; // 获取当前实例测量得出的总时间
string seconds = timespan.TotalSeconds.ToString("#0.00000000 "); // 总秒数
string minutes = timespan.TotalMinutes.ToString("#0.00000000 "); // 总分钟
string milliseconds = timespan.TotalMilliseconds.ToString("#0.00000000 "); // 总毫秒数
string hours = timespan.TotalHours.ToString("#0.00000000 "); // 总小时
浙公网安备 33010602011771号