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. [CodeEdit--Sublime]一些好用的Plugins

    Sublime Text 3 Plugins (**)packet control:plugin包管理器 (**)netuts-fetch: (**)markdown editing:Markdown ...

  2. 龙书(Dragon book) +鲸书(Whale book)+虎书(Tiger book)

    1.龙书(Dragon book)书名是Compilers: Principles,Techniques,and Tools作者是:Alfred V.Aho,Ravi Sethi,Jeffrey D. ...

  3. IPC——消息队列

    Linux进程间通信——使用消息队列 下面来说说如何用不用消息队列来进行进程间的通信,消息队列与命名管道有很多相似之处.有关命名管道的更多内容可以参阅我的另一篇文章:Linux进程间通信——使用命名管 ...

  4. 在Ubuntu 14.04 64bit上安装numpy和matplotlib库

    原文:http://blog.csdn.net/tao_627/article/details/44004541 按照这个成功安装! 机器学习是数据挖掘的一种实现形式,在学习<机器学习实战> ...

  5. Systemd 入门教程:实战篇

    Systemd 入门教程:实战篇 上一篇文章,介绍了 Systemd 的主要命令,这篇文章主要介绍如何使用 Systemd 来管理我们的服务,以及各项的含义: 一.开机启动 对于那些支持 System ...

  6. STC51系列单片机免掉电下载(热启动下载)

    相信喜欢单片机的朋友都用过STC的单片机,用过STC单片机的朋友都有这种感受:实惠.易用.功能强大!就是每次下载都要冷启动特别恶心,相信很多朋友的开发板上的电源键都按烂了. 其实STC单片机可以不用免 ...

  7. Doing Homework 状态压缩DP

    Doing Homework 题目抽象:给出n个task的name,deadline,need.  每个任务的罚时penalty=finish-deadline;   task不可以同时做.问按怎样的 ...

  8. 使用sharepreferce记录数组数据

    使用sharepreferce记录数组数据 /** * * sharepreference纪录news数据 * * */ private static final String name=" ...

  9. UIScrollView做循环图片

    #import "ViewController.h" #define IMAGE_COUNT 6 @interface ViewController () { UIImageVie ...

  10. Android&iOS崩溃堆栈上报

    Android&iOS崩溃堆栈上报 原文地址:http://www.cnblogs.com/songcf/p/4885468.html 通过崩溃捕获和收集,可以收集到已发布应用(游戏)的异常, ...