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

首頁(yè) > 學(xué)院 > 開(kāi)發(fā)設(shè)計(jì) > 正文

【轉(zhuǎn)載】#323

2019-11-17 03:18:37
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友

【轉(zhuǎn)載】#323 - A Generic Class is a Template for a Class

A generic classs is a class that takes one or more type parameters, which it then uses in the definition of the class. It can be thought of as a template for a class.

1 public class ThingContainer<TParam>2 {3   PRivate TParam theThing;4 5   public void SetThing(TParam newValue)6   {7     theThing = newValue;8   }9 }

You use a generic class by specifying a type for each of the type parameters.

1 ThingContainer<int> intContainer = new ThingContainer<int>();2 intContainer.SetThing(5);3 4 ThingContainer<Dog> dogContainer = new ThingContainer<Dog>();5 dogContainer.SetThing(new Dog("Kirby", 5));

In this example, we use a generic class to store an object of an arbitary type. We use one version of the class to store an int and another to store a Dog. Notice that wherever we use the name of the generic class to define an instance, we need to supply a typename (e.g. int, Dog) as a parameter.

原文地址:#323 - A Generic Class is a Template for a Class


發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 溧水县| 宝坻区| 甘孜县| 抚宁县| 乐亭县| 井陉县| 青州市| 襄汾县| 黄冈市| 晋州市| 敦化市| 兴义市| 梁河县| 赞皇县| 漾濞| 榆社县| 肃宁县| 临夏市| 镇安县| 江门市| 海门市| 娄烦县| 丰都县| 平阴县| 皮山县| 西峡县| 新营市| 仙游县| 通山县| 大埔县| 亚东县| 溧阳市| 南康市| 遂平县| 六安市| 黔南| 日喀则市| 乐陵市| 枞阳县| 吴旗县| 尉氏县|