【转载】#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 ...
随机推荐
- 使用NPOI导出DataTable到Excel
使用C#对DataTable导出到Excel是我们工作当中比较多用到的场景,微软提供了Microsoft.Office.Interop.Excel组件可以进行操作,但是该组件在数据量大的时候速度很慢, ...
- iOS开发——动画编程Swift篇&(三)CATransition动画
CATransition动画 // MARK: - CATransition动画 // /* 动画样式 */ // let kCATransitionFade: NSString! //翻页 // l ...
- Java RESTful Web Service相关概念
原文地址:http://1.liangtao.sinaapp.com/?p=647 接上一篇文章REST|RESTful初步认识:p=639">http://1.liangtao.si ...
- centos 服务器配置(三) 之定时任务
有些liunx系统已经自带定时任务crontab,但是有的新装系统还未安装定时任务,这个时候就需要我们手动对其进行安装. 安装crontab: yum install crontabs 说明: /sb ...
- Mip-Mapping很重要
MipMap这个东东,记得我除了最早在DX9龙书上了解了其基本概念后,以后便再没接触过,因为从创建到使用都是硬件一手包办,所以这个知识点很容易被遗忘和忽视.这几天空闲时恰好发现了一点MipMap引起的 ...
- Jquery实现页面上所有的checkbox只能选中一个
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <hea ...
- Servlet 3.0 新特性
Servlet 3.0 作为 Java EE 6 规范体系中一员,随着 Java EE 6 规范一起发布.该版本在前一版本(Servlet 2.5)的基础上提供了若干新特性用于简化 Web 应用的开发 ...
- 终端I/O之获得和设置终端属性
使用函数tcgetattr和tcsetattr可以获得或设置termios结构.这样也可以检测和修改各种终端选择标志和特殊字符,以使终端按我们所希望的方式进程操作. #include <term ...
- jQuery刷新div内容,并对刷新后元素绑定事件。$(document).on()
给id=zt的元素绑定点击事件 点击刷新id=ps_list中类容(内容中含有id=zt元素) 把zt的点击事件委托到了document上,这样就不用考虑事件是否能绑定到新加元素上 代码如下: $(d ...
- 编译器失败,错误代码为xxx
问题:出现编译器失败,等一会儿出现csc.exe无响应,错误代码不一定是255,是其他的也可以试试 解决办法: 查看是否类似360之类的杀毒软件运行着,如果运行着,关掉然后重新试一下,应该就没有问题了 ...