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的更多相关文章

  1. 关于C#你应该知道的2000件事

    原文 关于C#你应该知道的2000件事 下面列出了迄今为止你应该了解的关于C#博客的2000件事的所有帖子. 帖子总数= 1,219 大会 #11 -检查IL使用程序Ildasm.exe d #179 ...

  2. C++学习指南

    转载于stackoverflow:http://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list 感谢Ge ...

  3. linux基础-第十四单元 Linux网络原理及基础设置

    第十四单元 Linux网络原理及基础设置 三种网卡模式图 使用ifconfig命令来维护网络 ifconfig命令的功能 ifconfig命令的用法举例 使用ifup和ifdown命令启动和停止网卡 ...

  4. The Definitive C++ Book Guide and List

    学习c++的书单 转自 http://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list Beginner ...

  5. T4模板试水篇1_入门

    T4模板作为VS自带的一套代码生成器,功能有多强大我也不知道,最近查找了一些资料学习一下,做个笔记 更详细的资料参见: MSDN: http://msdn.microsoft.com/zh-cn/li ...

  6. (原) c++ 杂

    Declaration of variables   C++ is a strongly-typed language, and requires every variable to be decla ...

  7. (转) Overloads and templates

    Overloaded functions In C++, two different functions can have the same name if their parameters are ...

  8. 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 ...

  9. zabbix系列之六——安装后配置二Items

    https://www.zabbix.com/documentation/3.4/manual/config/items/itemtypes/snmp 1Items 1.1creating items ...

随机推荐

  1. ibatis 分页的简单实现

    ibatis 物理分页的简单实现 cheungmine 2013-8-26 使用SSI (Struts2, Spring3, iBATIS2.3)框架开发Web服务的时候有一个需求就是对查询得到的结果 ...

  2. Center OS mongodb安装

    一.下载        1.#cd /usr/local/src     2.#wget http://fastdl.mongodb.org/linux/mongodb-linux-x86_64-2. ...

  3. gradle的maven plugin使用

    在分布式系统开发中,基于gradle的项目,要共享jar一般是借助maven私服.那么gradle的maven插件如何做到上传binary jar,source jar, javadoc jar到私服 ...

  4. [原创]SQL SERVER 2008R2安装

    配置系统环境说明 操作系统:Windows 7 操作系统版本:旗舰版 SP1 操作系统位数:x64 注:其它系统配置也基本相似,只是可能菜单的名字或者所处位置不一样,具体的配置如有不同,请自行搜索 安 ...

  5. 基于css3的文字3D翻转特效

    一款基于css3的文字3D翻转特效.这款特效当鼠标经过文字的时候3D翻转显示阴影.效果图如下: 在线预览   源码下载 实现的代码. html代码: <div class="compo ...

  6. The Kernel Newbie Corner: Kernel Debugging with proc "Sequence" Files--Part 2

    转载:https://www.linux.com/learn/linux-career-center/39972-kernel-debugging-with-proc-qsequenceq-files ...

  7. GNU C/C++ __attributes__ GCC中的弱符号与强符号

    最近在看一些源代码,遇到了一些使用__attribute__修饰函数和变量的属性方面的代码,不是太了解,很是汗颜,再此做个总结:   GCC使用__attribute__关键字来描述函数,变量和数据类 ...

  8. 学java入门到精通,不得不看的15本书

    学java入门到精通,不得不看的15本书 一.Java编程入门类1.<Java编程思想>2.<Agile Java>中文版 二.Java编程进阶类1.<重构 改善既有代码 ...

  9. 1.7.4.2 Local Parameters in Queries--局部参数

    1. 局部参数 Local parameters是在solr请求中指定一个查询参数.Local parameters提供了一个方式以添加元数据到某个参数类型中,如查询字符串(在solr文档中,Loca ...

  10. [设计模式] .NET设计模式笔记 - 有多少种设计模式

    .NET下的23中设计模式. ※创建型模式篇 ●单件模式(Single Pattern) ●抽象工厂模式(Abstract Factory) ●建造者模式(Builder Pattern) ●工厂方法 ...