国产探花免费观看_亚洲丰满少妇自慰呻吟_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ā)表
主站蜘蛛池模板: 双牌县| 泰安市| 丰原市| 莱阳市| 鄂托克旗| 祥云县| 文登市| 罗城| 改则县| 新河县| 金昌市| 云浮市| 柘城县| 上饶市| 黎城县| 托克逊县| 崇明县| 达孜县| 民县| 乌海市| 铜陵市| 西畴县| 古蔺县| 道孚县| 体育| 安达市| 五华县| 巴彦县| 汕尾市| 喀喇沁旗| 虞城县| 光山县| 玉环县| 石城县| 陆良县| 景泰县| 包头市| 正定县| 云安县| 张北县| 盈江县|