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. Codeforces 852D

    数目规模大,尝试转换为判定性问题,那么E就不影响到网络流的复杂度了 SPFA码歪了,WA了好几发气死了 #include<bits/stdc++.h> using namespace st ...

  2. CF 520 B. Two Buttons(bfs)

    /*题意:一个数,就是输入的第一个数,让它变成第二个数最少用几步.可以点红色按钮,蓝色按钮来改变数字,红色:*2,蓝色:-1,如果变成负数,就变成原来的数.CF 520 B. Two Buttons思 ...

  3. hdu 6287

    选出来比较合适的博客 https://blog.csdn.net/Tony5t4rk/article/details/80490711 https://blog.csdn.net/Game_Acm/a ...

  4. js随机生成[n,m)的数字(不包括m)

    Math.random();//随机生成0到1的数字 Math.floor();//取小整 Math.floor(Math.random()*(最大值 - 最小值) + 最小值) 生成2到8的数:Ma ...

  5. spring 事务 @EnableTransactionManagement原理

    @EnableXXX原理:注解上有个XXXRegistrar,或通过XXXSelector引入XXXRegistrar,XXXRegistrar实现了 ImportBeanDefinitionRegi ...

  6. Vim Plugins for Linux

    Usage 1.Set up Vundle: git clone https://github.com/VundleVim/Vundle.vim.git ~/.vim/bundle/Vundle.vi ...

  7. Silverlight FullScreen 全屏

    <UserControl x:Class="FullScreen.MainPage" xmlns="http://schemas.microsoft.com/win ...

  8. formatter easyui 重命名

    function for_method(){    datagridmethod = $('#formethod_datagrid').datagrid({            url : 'loc ...

  9. windows2008利用serv-u14.0.0.6架设FTP服务器的方法

    这几天在公司的服务器上安装serv-u,想把它做成可以传输文件的ftp服务器,结果遇到了很多问题,试了serv-u的好几个版本,结果都不行,最终只有serv-u14安装成功. 安装过程很简单,安装后除 ...

  10. 类模版的static成员

    类模版中声明static成员 template <class T> class Foo { public: static size_t count() { ++ctr; cout < ...