zoukankan      html  css  js  c++  java
  • c# 冒号之命名参数 转载

    在查看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,而现在,这个规矩可以被打破了。你可以自己随便什么顺序传入,这也在一定程度上提高了代码的可读性。例子:
    1         static void Main(string[] args)
    2         {
    3             TestMethod2(s: "ojlovecd", i: 26);
    4         }
    5         static void TestMethod2(int i, string s)
    6         {
    7             Console.WriteLine("i:{0},s:{1}", i, s);
    8         }
  • 相关阅读:
    doc
    doc
    doc
    doc
    doc
    doc
    doc
    doc
    java基础知识系列--- 反射,注解,泛型,内省
    CCProcxy代理服务器的配置使用
  • 原文地址:https://www.cnblogs.com/lyghost/p/2673177.html
Copyright © 2011-2022 走看看