A generic class includes one or more type parameters that will be substituted with actual types when the class is used. If the class has more than one type parameter, all parameters must be substituted when the class is used.

Here's an example of a generic class that stores two objects, each having its own type.

 public class ThingContainer<TThing1, TThing2>
{
private TThing1 thing1;
private TThing2 thing2; public void SetThings(TThing1 first, TThing2 second)
{
thing1 = first;
thing2 = second;
} public string DumpThings()
{
return string.Format("{0},{1}", thing1.ToString(), thing2.ToString());
}
}

We can use this class as follows:

 ThingContainer<string, int> cont1 = new ThingContainer<string, int>();
cont1.SetThings("Hemingway", );
Console.WriteLine(cont1.DumpThings()); ThingContainer<Dog, DateTime> cont2 = new ThingContainer<Dog, DateTime>();
cont2.SetThings(new Dog("Kirby", ), new DateTime(, , ));
Console.WriteLine(cont2.DumpThings());

原文地址:#324 - A Generic Class Can Have More than One Type Parameter

【转载】#324 - A Generic Class Can Have More than One Type Parameter的更多相关文章

  1. [TypeScript] Infer the Return Type of a Generic Function Type Parameter

    When working with conditionals types, within the “extends” expression, we can use the “infer” keywor ...

  2. 【转载】#458 Errors While Converting Between enum and Underlying Type

    You can convert to an enum value from its underlying type by casting the underlying type (e.g. int) ...

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

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

  4. Hibernate Validator 6.0.9.Final - JSR 380 Reference Implementation: Reference Guide

    Preface Validating data is a common task that occurs throughout all application layers, from the pre ...

  5. cs108 03 ( 调试, java通用性)

    Debuger Great questions These questions will solve most bugs: what method shows the symptom ? what l ...

  6. C# Generic(转载)

    型(generic)是C#语言2.0和通用语言运行时(CLR)的一个新特性.泛型为.NET框架引入了类型参数(type parameters)的概念.类型参数使得设计类和方法时,不必确定一个或多个具体 ...

  7. C#:泛型(Generic)

    前言:  此系列都为个人对C#的回顾,属于个人理解,新司机可参考.求老司机指点.如果有什么问题或不同见解,欢迎大家与我沟通! 目录:  泛型是什么 泛型的好处及用途 如何声明使用泛型 泛型类 泛型方法 ...

  8. 转载:《TypeScript 中文入门教程》 9、泛型

    版权 文章转载自:https://github.com/zhongsp 建议您直接跳转到上面的网址查看最新版本. 介绍 软件工程中,我们不仅要创建一致的定义良好的API,同时也要考虑可重用性. 组件不 ...

  9. 转载:C#中的泛型

    泛型(generic)是C#语言2.0和通用语言运行时(CLR)的一个新特性.泛型为.NET框架引入了类型参数(type parameters)的概念.类型参数使得设计类和方法时,不必确定一个或多个具 ...

随机推荐

  1. Flask&&人工智能AI -- 8 HTML5+ 初识,HBuilder,夜神模拟器,Webview

    昨日内容回顾 1.增删改查: 增: db.collections.insert({a:1}) // 官方不推荐了 db.collections.insertMany([{a:1},{b:1}]) in ...

  2. java中Runtime类和Process类的简单介绍

    在java.lang包当中定义了一个Runtime类,在java中对于Runtime类的定义如下: Java code public class Runtime extends Object 每个 J ...

  3. php数组·的方法-数组与数据结构

    /*数组与数据结构*/ //shuffle() 随机打乱数组 //array_push() 数组末尾添加元素 //array_pop() 数组末尾删除元素 //array_shift() 数组首位删除 ...

  4. maya安装错误

    AUTODESK系列软件着实令人头疼,安装失败之后不能完全卸载!!!(比如maya,cad,3dsmax等).有时手动删除注册表重装之后还是会出现各种问题,每个版本的C++Runtime和.NET f ...

  5. Java基础09-循环结构

    1.while循环(循环次数不确定的情况通常用这个) 特点:先判断,再执行 public class Test{ public static void main(String[] args){ int ...

  6. Kudu的Using Apache Kudu with Apache Impala(官网推荐的步骤)

    不多说,直接上干货! http://kudu.apache.org/docs/kudu_impala_integration.html http://blog.csdn.net/lovebyz/art ...

  7. Kudu版本升级(官网推荐的步骤)(Upgrade from a Previous Version of Kudu)

    不多说,直接上干货! http://kudu.apache.org/docs/installation.html#sles_from_source

  8. 用信鸽来解释 HTTPS

    原文:http://blog.jobbole.com/113883/ ----------------------------------------------------------------- ...

  9. 详解在Hibernate中配置数据库方言的作用和好处以及各种数据库的方言连接

    Hibernate底层依然使用SQL语句来执行数据库操作,虽然所有关系型数据库都支持使用标准SQL语句,但所有数据库都对标准SQL进行了一些扩展,所以在语法细节上存在一些差异,因此Hibernate需 ...

  10. ETL模型设计

    传统的关系数据库一般采用二维数表的形式来表示数据,一个维是行,另一个维是列,行和列的交叉处就是数据元素.关系数据的基础是关系数据库模型,通过标准的SQL语言来加以实现. 数据仓库是多维数据库,它扩展了 ...