【转载】#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.
public class ThingContainer<TParam>
{
private TParam theThing; public void SetThing(TParam newValue)
{
theThing = newValue;
}
}
You use a generic class by specifying a type for each of the type parameters.
ThingContainer<int> intContainer = new ThingContainer<int>();
intContainer.SetThing(); ThingContainer<Dog> dogContainer = new ThingContainer<Dog>();
dogContainer.SetThing(new Dog("Kirby", ));
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
【转载】#323 - A Generic Class is a Template for a Class的更多相关文章
- 关于C#你应该知道的2000件事
原文 关于C#你应该知道的2000件事 下面列出了迄今为止你应该了解的关于C#博客的2000件事的所有帖子. 帖子总数= 1,219 大会 #11 -检查IL使用程序Ildasm.exe d #179 ...
- C++学习指南
转载于stackoverflow:http://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list 感谢Ge ...
- linux基础-第十四单元 Linux网络原理及基础设置
第十四单元 Linux网络原理及基础设置 三种网卡模式图 使用ifconfig命令来维护网络 ifconfig命令的功能 ifconfig命令的用法举例 使用ifup和ifdown命令启动和停止网卡 ...
- The Definitive C++ Book Guide and List
学习c++的书单 转自 http://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list Beginner ...
- T4模板试水篇1_入门
T4模板作为VS自带的一套代码生成器,功能有多强大我也不知道,最近查找了一些资料学习一下,做个笔记 更详细的资料参见: MSDN: http://msdn.microsoft.com/zh-cn/li ...
- (原) c++ 杂
Declaration of variables C++ is a strongly-typed language, and requires every variable to be decla ...
- (转) Overloads and templates
Overloaded functions In C++, two different functions can have the same name if their parameters are ...
- Writing your first Django
Quick install guide 1.1 Install Python, it works with Python2.6, 2.7, 3.2, 3.3. All these version ...
- zabbix系列之六——安装后配置二Items
https://www.zabbix.com/documentation/3.4/manual/config/items/itemtypes/snmp 1Items 1.1creating items ...
随机推荐
- vs2013 设置为中文版
- Android端百度地图API使用详解
百度地图API简介 百度地图移动版API(Android)是一套基于Android设备的应用程序接口,通过该接口,可以轻松的访问百度服务和数据,构建功能丰富.交互性强的地图应用程序. 百度地图移动版A ...
- 字典树(Trie)的java实现
一.定义 字典树又称单词查找树,Trie树,是一种树形结构,是一种哈希树的变种.典型应用是用于统计,排序和保存大量的字符串(但不仅限于字符串),所以经常被搜索引擎系统用于文本词频统计.它的优点是:利用 ...
- eclipse[downloads]
下载J2EE:http://www.eclipse.org/downloads/ 下载WPT插件:http://download.eclipse.org/webtools/updates 下载TOMC ...
- org-reveal
环境: Debian 8 Emacs 24.4 org-reveal是在emacs org-mode中使用reveal.js的一个插件. emacs 24.4自带的org版本是8.2.10,这个版本似 ...
- 错误"Lc.exe 已退出,代码 -1 "
今天做项目的时候突然出现编译不通过,错误为Lc.exe已退出,代码为-1.这让我郁闷了至少30分钟,后来上网查了一下,才知道原因所在,我们项目中使用了第三方组件(Infragistics)造成的,至于 ...
- 【Java线程池快速学习教程】
1. Java线程池 线程池:顾名思义,用一个池子装载多个线程,使用池子去管理多个线程. 问题来源:应用大量通过new Thread()方法创建执行时间短的线程,较大的消耗系统资源并且系统的响应速度变 ...
- 重构4-Push Down Method(方法下移)
我们介绍了将方法迁移到基类以供多个子类使用的上移方法重构,今天我们来看看相反的操作.重构前的代码如下: public abstract class Animal { public void Bark( ...
- css初接触
一.简介:CSS 即 级联样式表 . 它是一种用来表现HTML(标准通用标记语言的一个应用)或XML(标准通用标记语言的一个子集)等文件样式的计算机语言. css是能够真正做到网页表现与内容分离的一种 ...
- C语言中的命名空间
C语言中的命名空间 命名空间是为了解决 "在相同作用域内如何区分 相同的标识符". 说明: ①只有在相同作用域的情况下才能使用到命名空间去区分标识符,在嵌套的作用域.不同的作用域区 ...