【转载】#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 ...
随机推荐
- 网站性能扩展案例:每天30-50亿请求,300K QPS是如何炼成的
Reduce Data广告服务网站(http://reducedata.com)如何扩展到每天300K QPS请求?分享经验如下: 1. 为大规模而设计,广告服务平台从一开始增长就很惊人,因此,系统开 ...
- [Angular2 Router] Lazy Load Angular 2 Modules with the Router
Angular 2 lazy loading is a core feature of Angular 2. Lazy loading allows your application to start ...
- iOS开发——UI篇Swift篇&UIDatePicker
UIDatePicker //返回按钮事件 @IBAction func backButtonClick() { self.navigationController?.popViewControlle ...
- Web service是什么?(转)
我认为,下一代互联网软件将建立在Web service(也就是"云")的基础上. 我把学习笔记和学习心得,放到网志上,欢迎指正. 今天先写一个最基本的问题,Web service到 ...
- Javascript禁止子元素继承父元素的事件
3种方法1.在父元素事件的function中加if(event.target==this){ }2.子元素事件function最后加event.stopPropgation():// 阻止事件冒泡3. ...
- c++ 构造函数,拷贝构造函数,析构函数与赋值操作符
题目: 为下面的Rectangle类实现构造函数,拷贝构造函数,赋值操作符,析构函数. class Shape { int no; }; class Point { int x; int y; }; ...
- weak 弱引用的实现方式
来源:冬瓜争做全栈瓜 链接:https://desgard.com/weak/ 对于 runtime 的分析还有很长的路,最近在写 block 系列的同时,也回顾一下之前疏漏的细节知识.这篇文章是关于 ...
- B. Pasha and String
time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standa ...
- Android小项目之八 界面细节
------- 源自梦想.永远是你IT事业的好友.只是勇敢地说出我学到! ---------- 按惯例,写在前面的:可能在学习Android的过程中,大家会和我一样,学习过大量的基础知识,很多的知识点 ...
- leetcode 题解: Length of Last Word
leetcode: Given a string s consists of upper/lower-case alphabets and empty space characters ' ', re ...