国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

【轉載】#324

2019-11-17 03:18:35
字體:
來源:轉載
供稿:網友

【轉載】#324 - A Generic Class Can Have More than One Type Parameter

A generic class includes one or more type parameters that will be substituted with actual types when the class is used. If the class has more than one type parameter, all parameters must be substituted when the class is used.

Here's an example of a generic class that stores two objects, each having its own type.

 1 public class ThingContainer<TThing1, TThing2> 2 { 3     PRivate TThing1 thing1; 4     private TThing2 thing2; 5  6     public void SetThings(TThing1 first, TThing2 second) 7     { 8         thing1 = first; 9         thing2 = second;10     }11 12     public string DumpThings()13     {14         return string.Format("{0},{1}", thing1.ToString(),             thing2.ToString());15     }            16 }            

We can use this class as follows:

1 ThingContainer<string, int> cont1 = new ThingContainer<string, int>();2 cont1.SetThings("Hemingway", 1899);3 Console.WriteLine(cont1.DumpThings());   4 5 ThingContainer<Dog, DateTime> cont2 = new ThingContainer<Dog, DateTime>();6 cont2.SetThings(new Dog("Kirby", 14), new DateTime(1998, 5, 1));7 Console.WriteLine(cont2.DumpThings());  

原文地址:#324 - A Generic Class Can Have More than One Type Parameter


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 昆山市| 兴义市| 香河县| 榆林市| 井陉县| 西安市| 闻喜县| 工布江达县| 白水县| 绥江县| 习水县| 芦山县| 宜兰市| 沿河| 四平市| 平远县| 陈巴尔虎旗| 铜川市| 宿迁市| 门源| 中江县| 临夏县| 青冈县| 河池市| 台北县| 吴忠市| 河北省| 大新县| 叙永县| 双流县| 博爱县| 益阳市| 海阳市| 米易县| 长海县| 泽普县| 山丹县| 长治市| 江阴市| 从化市| 冕宁县|