【转载】#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 ...
随机推荐
- 深入研究Clang(三) libclang
作者:史宁宁 如今的Clang,不不过一个编译器前端,同一时候也能够作为一个库使用.作为一个库使用的时候,能够用它去分析C/C++/ObjectC语言代码,能够分析源代码得到AST,也能够获取已经分析 ...
- AndroidManifest.xml 详解 (四) 之uses-permission
The <uses-permission> Element 我们现在告别<application>元素,回到<manifest>中定义的子元素,<uses-p ...
- 如何在HTML5 图片预览
HTML5的 File API允许浏览器访问本地文件系统,借助它我们可以实现以前无法实现的本地图片预览功能. 先介绍下该API实现了那些接口: 1.Blob接口,表示原始的二进制数据,通过它可以访问到 ...
- Ubuntu下VSFTPD(六)(常见FTP命令及其功能) (
常见FTP命令及其功能 FTP 命令 功能 FTP 命令 功能 ls 显示服务器上的目录 ls [remote-dir][local-file] 显示远程目录remote-dir,并存入本地文件 ...
- 对lua继承中self.__index = self的释疑
首先看看从lua表中查找一个键时的流程: -- 当从表t中查找键k时,lua处理如下: -- 1.t中是否有k,有则直接返回值,否则第2步 -- 2.t是否有元表, 无则返回nil, 有则第3步 -- ...
- php与mysql通讯那点事
php与mysql通讯那点事 http://www.cnxct.com/libmysql-mysqlnd-which-is-best-and-what-about-mysqli-pdomysql-my ...
- javascript冷知识
本人很少写博客,所以文笔很不好,如果解释的不够清楚的,欢迎点评 1.+号(一元加操作符): 如果放在数值前的话,对数值不会产生任何影响,不过放在其他的数据类型前面的话,就等于调用number()将他转 ...
- org.apache.solr.common.util.ContentStream.java及其实现类
org.apache.solr.common.util.ContentStream.java 主要是获取文件,URL,字节数组,字符串等的数据流.主要方法又InputStream getStream( ...
- Remap BMW F11 2010 all ECUs with E-Sys and ENET cable
Just wanted to share some experiences remaping all the ECUs in my F11 2010 BMW, hopefully other BMW ...
- 2. Android框架和工具之 Volley
Java基础知识强化之网络编程笔记23:Android网络通信之 Volley(Google开源网络通信库)