网站首页 美食营养 游戏数码 手工爱好 生活家居 健康养生 运动户外 职场理财 情感交际 母婴教育 时尚美容 知识问答

C# 5.0 新特性介绍

时间:2024-10-14 04:05:22

1、创建【控制台应用程序】项目【CSharp.NewFeatures.V50】

C# 5.0 新特性介绍

3、测试辅助类【CSharpV50】的代码如下:1)方法AwaitFunctionAsync:用于测试异步特性 /// <summary> /// 使用 async 实现异步方法 /// </summary> public async void AwaitFunctionAsync() { Console.WriteLine("进入async方法 " + DateTime.Now.ToString()); await Task.Delay(1000); Console.WriteLine("结束async方法 " + DateTime.Now.ToString()); }

C# 5.0 新特性介绍

5、Main方法的整体测试结构如下:记得需要在Main方法内部结尾处添加代码:Console.ReadLine(); 用于停住命令行显示界面,看测试结果,否则,看不到结果

C# 5.0 新特性介绍

7、Main方法内部的Caller Information测试代艨位雅剖码如下:// 1)CallerFileP锾攒揉敫athAttribute:编译期的调用方的路径(注意是编译期的物理路径,不管放到哪里运行,都是编译期的路径)// 2)CallerLineNumberAttribute:方法调用处的行号(即下面例子 sharpV50.InsertLog(); 在当前文件中的行号 )// 3)CallerMemberNameAttribute:调用方的方法或者属性(即此处的main方法名)#region 2、Caller Information Console.WriteLine("============= 【Caller Information】 Start ==========="); // 1)CallerFilePathAttribute:编译期的调用方的路径(注意是编译期的物理路径,不管放到哪里运行,都是编译期的路径) // 2)CallerLineNumberAttribute:方法调用处的行号(即下面例子 sharpV50.InsertLog(); 在当前文件中的行号 ) // 3)CallerMemberNameAttribute:调用方的方法或者属性(即此处的main方法名) // 4)上述标记是修饰方法的参数的 sharpV50.InsertLog(); Console.WriteLine("============= 【Caller Information】 End ==========="); Console.WriteLine(); Console.WriteLine(); #endregion

C# 5.0 新特性介绍
© 2025 小知经验
信息来自网络 所有数据仅供参考
有疑问请联系站长 site.kefu@gmail.com