亚洲激情专区-91九色丨porny丨老师-久久久久久久女国产乱让韩-国产精品午夜小视频观看

溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

#讀書筆記#Illustrated C# 2012第17章 Generics泛型(2)

發布時間:2020-06-24 12:23:38 來源:網絡 閱讀:518 作者:lsieun 欄目:編程語言

=================

4、泛型方法Generic Methods 

Unlike the other generics, a method is not a type but a member. You can declare generic methods in both generic and nongeneric classes, and in structs and interfaces.

#讀書筆記#Illustrated C# 2012第17章 Generics泛型(2)

4.1、Declaring a Generic Method

Generic methods have a type parameter list and optional constraints. 

 Generic methods have two parameter lists: 

  •  The method parameter list, enclosed in parentheses. 

  •  The type parameter list, enclosed in angle brackets. 

 To declare a generic method, do the following: 

Place the type parameter list immediately after the method name and before the method parameter list

Place any constraint clauses after the method parameter list.

#讀書筆記#Illustrated C# 2012第17章 Generics泛型(2)

Note:Remember that the type parameter list goes after the method name and before the method parameter list.


4.2、Invoking a Generic Method 

To invoke a generic method, supply type arguments with the method invocation

#讀書筆記#Illustrated C# 2012第17章 Generics泛型(2)

4.3、Extension Methods with Generic Classes 

Extension methods work just as well with generic classes. They allow you to associate a static method in one class with a different generic class and to invoke the method as if it were an instance method on a constructed instance of the class. 


As with nongeneric classes, an extension method for a generic class must satisfy the following constraints: 

  1.  It must be declared static. (方法是靜態的)

  2.  It must be the member of a static class. (類是靜態)

  3.  It must contain as its first parameter type the keyword this, followed by the name of the generic class it extends. 


=================

5、泛型結構Generic Structs

Like generic classes, generic structs can have type parameters and constraints. The rules and conditions for generic structs are the same as those for generic classes. 


=================

6、泛型委托Generic Delegates 

Generic delegates are very much like nongeneric delegates, except that the type parameters determine the characteristics of what methods will be accepted. 

 To declare a generic delegate, place the type parameter list in angle brackets after the delegate name and before the delegate parameter list.(位置)

 

 Notice that there are two parameter lists: the delegate formal parameter list and the type parameter list. (兩處parameter list)

 The scope of the type parameters includes the following: 

 The return type 

 The formal parameter list 

 The constraint clauses


=================

7、泛型接口Generic Interfaces 

Generic interfaces allow you to write interfaces where the formal parameters and return types of interface members are generic type parameters. Generic interface declarations are similar to nongeneric interface declarations, but have the type parameter list in angle brackets after the interface name. 


generic type declaration + type arguments --> a constructed type


向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

上栗县| 孟州市| 荆州市| 玛纳斯县| 罗田县| 阿城市| 丽江市| 和龙市| 略阳县| 诸城市| 蒲城县| 临城县| 沁源县| 迁安市| 长海县| 昌邑市| 璧山县| 嵊泗县| 宁晋县| 建水县| 新郑市| 敖汉旗| 临桂县| 天台县| 沙湾县| 赫章县| 额济纳旗| 石棉县| 安溪县| 玉门市| 禹城市| 锦州市| 黄冈市| 鲁甸县| 乌鲁木齐市| 武强县| 英山县| 福泉市| 西城区| 榆社县| 太谷县|