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. Newtonsoft.Json 自定义序列化格式转化器

    public static class JsonHelper { static JsonHelper() { Newtonsoft.Json.JsonSerializerSettings settin ...

  2. MetricStatTimer

    package org.apache.storm.metric.internal; import java.util.Timer; /** * Just holds a singleton metri ...

  3. 自动截取sql并合并,生成执行HQL

    ### 提取SQL语句 FILE_PATH="/data/SCRIPT" cat tables | while read file do echo "-----> ...

  4. SQL SEVER 数据库日志(Log)文件增长过快的处理

    SQL SERVER 2016数据库,50GB+的数据.有大量的增删和插入操作,数据库log文件变得异常的大,而且增长速度特别的快.周五log文件20GB,周一上班就成了200+GB了 因为数据库恢复 ...

  5. Cache一致性协议之MESI

    http://blog.csdn.net/muxiqingyang/article/details/6615199 Cache一致性协议之MESI 处理器上有一套完整的协议,来保证Cache一致性.比 ...

  6. 把js生成的内容放入网页原有的div上

    <script> ; ; //5列 ); ; var htmlstr="<table style='position:absolute;top:9%;left:10%; b ...

  7. jar包介绍

    1.基本jar包 4+1:4个核心(beans+core+context+expression)+一个依赖(commons-logging...)

  8. 管理员账户权限不足 解决方案 类似没有XXX权限之类的问题解决方法

  9. 内存分配详解 malloc, new, HeapAlloc, VirtualAlloc,GlobalAlloc

    很多地方都会使用内存,内存使用过程中操作不当就容易崩溃,无法运行程序,上网Google学习一下,了解整理下他们之间的区别以及使用 ,获益匪浅 0x01 各自的定义和理解 (1)先看GlobalAllo ...

  10. iOS实现头像选取(照相或者图片库)、大小等比缩放、生成圆形头像

    //弹出actionsheet.选择获取头像的方式 //从相册获取图片 -(void)takePictureClick:(UIButton *)sender { // /*注:使用,需要实现以下协议: ...