<output id="qn6qe"></output>

    1. <output id="qn6qe"><tt id="qn6qe"></tt></output>
    2. <strike id="qn6qe"></strike>

      亚洲 日本 欧洲 欧美 视频,日韩中文字幕有码av,一本一道av中文字幕无码,国产线播放免费人成视频播放,人妻少妇偷人无码视频,日夜啪啪一区二区三区,国产尤物精品自在拍视频首页,久热这里只有精品12
      happyhippy

      這個世界的問題在于聰明人充滿疑惑,而傻子們堅信不疑。--羅素

      0. Auto-Implemented Properties:
      (1). Auto-implemented properties make property-declaration more concise when no additional logic is required
      in the property accessors. When you declare a property as shown in the following example, the compiler creates a private, anonymous backing field can only be accessed through the property's get and set accessors.
      (2). 代碼示例:

      1class LightweightCustomer
      2{
      3    public double TotalPurchases getset; }
      4    public string Name getprivate set; } // read-only
      5    public int CustomerID getprivate set; } // read-only
      6}



      1. Object initializers
      (1). Object initializers let you assign values to any accessible fields or properties of an object at creation time without having to explicitly invoke a constructor. The following example(參考3中的Anonymous Types) shows how to use an object initializer with a named type.
      (2). 本質上是先調用無參構造函數創建一個臨時對象,然后對臨時對象對外公開(public/internal)的屬性/字段賦值,最后將臨時對象賦值給代碼中聲明的引用。由于這里需要調用無參構造函數,所以只能在具有無參構造函數(如果定義類型時,沒有給類型定義構造函數,則編譯器會自動給類添加一個無參構造函數)的類型實例化時使用Object initializers。


      2. Collection Initializers
      (1). Enables initialization of collections with an initialization list rather than specific calls to Add or another method.
      (2). 本質上也只是new個臨時collection,然后調用Add方法,最后將臨時集合賦值給代碼中聲明的集合引用


      3. Anonymous Types
      (1). Anonymous types provide a convenient way to encapsulate a set of read-only properties into a single object without having to first explicitly define a type.
      (2). 示例:

      var employee1 = new { ID = Guid.NewGuid(), Name = "happyhippy" };
      var employee2 
      = new { Name = "happyhippy", ID = Guid.NewGuid() };

      本質上編譯生成的類型定義(可以通過Reflector/IL DASM查看):

      1internal sealed class <>f__AnonymousType0<<ID>j__TPar, <Name>j__TPar>
      2internal sealed class <>f__AnonymousType1<<Name>j__TPar, <ID>j__TPar>

      這里生成兩個internal泛型定義,用多了不知道會不會類型泛濫...
      (3). 既然類型是在編譯時就已經確定下來了,何不自己去定義呢。相比之下,下面的代碼不會只會產生一個類型定義:

      class Employee<T1,T2>
      {
          
      public T1 P1 getset; }
          
      public T2 P2 getset; }//屬性名看起來沒有上面的漂亮
      }

      Employee
      <Guid, string> employee1 = new Employee<Guid, string> { P1 = Guid.NewGuid(), P2 = "happyhippy" };
      Employee
      <string, Guid> employee2 = new Employee<string, Guid> { P1 = "happyhippy", P2 = Guid.NewGuid() };



      4. Extension Methods
      (1). Extend existing classes by using static methods that can be invoked by using instance method syntax.Their first parameter specifies which type the method operates on, and the parameter is preceded by the this modifier. Extension methods are only in scope when you explicitly import the namespace into your source code with a using directive.
      (2). 本質上是CSC編譯生成對靜態方法的調用的IL代碼;使用時看起來有點像編譯時多態;
      (3). 優先級:類型定義中的方法 > Client代碼所在命名空間中定義的Extension Methods > 其他命名空間(前提:必須先import命名空間)中定義的Extension Methods;如果定義了優先級相同且簽名相同的方法,會出現編譯時錯誤。
      (4). 示例,僅供演示用。
      public static class ExtensionMethod
      {
          public static string ToString(this string source)
          {
              return "3.5";
          }
      }
      使用:Console.WriteLine("3.0".ToString());
      輸出:3.0
      解釋:參考(3)中優先級的解釋。


      5. Lambda Expressions
      (1). A lambda expression is an anonymous function that can contain expressions and statements, and can be used to create delegates or expression tree types.
      (2). 在2.0中的Anonymous Method Delegate的基礎上又包了一層糖,本質上都是編譯生成Named Delegate。
      (3). 語法:
      (input parameters) => expression
      (input parameters) => {statement;}

      6. Partial Methods
      (1). A partial class or struct may contain a partial method. One part of the class contains the signature of the method. An optional implementation may be defined in the same part or another part. If the implementation is not supplied, then the method and all calls to the method are removed at compile time.
      (2). MSDN上號稱的作用:Partial methods are especially useful as a way to customize generated code. They allow for a method name and signature to be reserved, so that generated code can call the method but the developer can decide whether to implement the method. Much like partial classes, partial methods enable code created by a code generator and code created by a human developer to work together without run-time costs.
      (3). 示例:

      // Definition in file1.cs
      partial void onNameChanged();
      // Implementation in file2.cs
      partial void onNameChanged()
      {
        
      // method body
      }

      (4). N多限制:
      標識為partial,返回值必須為void;
      可以使用ref參數,但不能使用out參數;
      partial methods默認的訪問級別是private, 不能在上面應用virtual;
      Partial methods上不能應用extern,因為方法體已經決定了它是否已定義及具體實現;
      Partial methods上可以應用static或unsafe修飾符;
      Partial methods可以是泛型方法;
      Cannot make a delegate to a partial method.


      posted on 2008-01-17 19:50  Silent Void  閱讀(1341)  評論(0)    收藏  舉報

      主站蜘蛛池模板: 国产一区二区精品久久岳| 日本免费一区二区三区日本| 精品一区二区久久久久久久网站| VA在线看国产免费| 久久亚洲熟女cc98cm| 日韩乱码人妻无码中文字幕视频| 日本妇人成熟免费| 爱色精品视频一区二区| 国产熟女高潮一区二区三区| 少妇仑乱a毛片无码| 精品人妻日韩中文字幕| 老男人久久青草av高清| 国产午夜美女福利短视频| 国产精品亚洲av三区色| 无码专区 人妻系列 在线| 国产在线无码精品无码| 亚洲国产成人无码网站大全| 无码日韩精品一区二区三区免费| 性姿势真人免费视频放| 成人看的污污超级黄网站免费| 五十路丰满中年熟女中出| 亚洲中文字幕av不卡无码| 视频一区视频二区制服丝袜 | 熟妇的味道hd中文字幕| 噜噜噜亚洲色成人网站∨| 亚洲偷自拍国综合| 亚洲av永久无码精品天堂久久| 黄页网站在线观看免费视频| 米林县| 一亚洲一区二区中文字幕| 中文有无人妻vs无码人妻激烈| 国产欧美日韩综合精品一区二区| 久久天天躁夜夜躁狠狠躁2022| 中文人妻av高清一区二区| 国产免费丝袜调教视频| 亚洲一区二区av免费| 一区二区三区精品不卡| 在线人人车操人人看视频| 国内自产少妇自拍区免费| 精品超清无码视频在线观看| 日本强伦片中文字幕免费看|