看啥推荐读物
专栏名称: dotNET跨平台
专注于.NET Core的技术传播。在这里你可以谈微软.NET,Mono的跨平台开发技术。在这里可以让你的.NET项目有新的思路,不局限于微软的技术栈,横跨Windows,Linux 主流平台
今天看啥  ›  专栏  ›  dotNET跨平台

.net5或.net6(Preview) 之 顶级语句

dotNET跨平台  · 公众号  ·  · 2021-06-02 07:45
创建一个控制台项目,.net5或.net6(Preview),在Program.cs中写如下代码,F5,能顺利跑起来,没有Program类,没有Main函数。这是C#9带来的顶级语句的功能。System.Console.WriteLine("你好,C#");其实这里的Program类和Main还是存在的,只是一种略写法,可以用如下代码看出来:System.Console.WriteLine($"Method Name:{System.Reflection.MethodBase.GetCurrentMethod().Name}");System.Console.WriteLine($"Class Name:{System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name}");System.Console.WriteLine($"Namespace Name:{System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Namespace}");System.Console.WriteLine($"Assembly Name:{System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Assembly.FullName}");System.Console.WriteLine($"Module Name:{System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Modu ………………………………

原文地址:访问原文地址
快照地址: 访问文章快照