在查看ADO.NET Entity Framework中得代码生成模板时,遇到这样一句代码:

<#=Accessibility.ForType(enumType)#> enum <#=code.Escape(enumType)#> : <#=code.Escape(enumType.UnderlyingType.ClrEquivalentType, fullyQualifySystemTypes: false)#>

 

其中:fullyQualifySystemTypes:false 当时使我疑惑,后来查阅相关资料:
这种用法是.net 4.0中得新特性,谓之命名参数。
 
在之前版本的C#中,方法定义的参数顺序必须与方法调用时的参数顺序一致,即方法Method(int i, string s)调用时就必须第一个传入int,第二个传入string,而现在,这个规矩可以被打破了。你可以自己随便什么顺序传入,这也在一定程度上提高了代码的可读性。例子:
C# code
static void Main(string[] args) { TestMethod2(s: "ojlovecd", i: 26); } static void TestMethod2(int i, string s) { Console.WriteLine("i:{0},s:{1}", i, s); }

相关文章:

  • 2021-07-06
  • 2021-10-10
  • 2022-12-23
  • 2022-01-11
  • 2021-07-28
  • 2021-08-17
  • 2021-10-02
  • 2021-09-06
猜你喜欢
  • 2022-12-23
  • 2022-02-20
  • 2022-12-23
  • 2021-11-23
  • 2021-10-14
相关资源
相似解决方案