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. day16 类之间的关系 特殊成员

    类与类之间的关系1.依赖关系(一个对象当另一个对象的参数)  关系最浅, 特殊成员: 1. 类名() 会自动调用 __init__() class Foo: def__init__(self, nam ...

  2. Java发送http请求(get 与post方法请求)

    转载:https://www.cnblogs.com/zzw1994/p/5140538.html

  3. 导入json文件报错,TypeError expected string or buffer

    导入json文件报错,TypeError expected string or buffer 原因:用字符串赋值后,python会把双引号转换为单引号 import json data = [{&qu ...

  4. thinkPHP5.0联表查询和统计文章的图片(栏目文章)数量

    public function index(){ //获取内容列表信息 $res = db('article')->alias('a') ->join('category b', 'b.i ...

  5. oracle 12.1.0.2的mgmt 导致的ORA-01017 bug

    两节点12c RAC,在两节点上export ORACLE_SID再sqlplus / as sysdba都正常登录,然而Commvault通过service_name方式(sqlplus sys/p ...

  6. Android NDK开发 Jni中打日志LOG(二)

    HelloJni.c文件中,加入头文件和函数声明.最终文件如下: #include <jni.h> #include <string.h> #include<androi ...

  7. 5W1H

    WHY   ——为什么做?原因与目标 WHAT ——做什么?目标与内容 WHO   ——谁去做?具体的执行者 WHEN ——什么时间做?执行时间 WHERE——在什么地方做?执行地点 HOW——怎样做 ...

  8. 还是畅通工程(prim和kruskal)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1233 还是畅通工程 Time Limit: 4000/2000 MS (Java/Others)    ...

  9. suau 公约公倍

    8619 公约公倍 时间限制:500MS  内存限制:1000K 提交次数:475 通过次数:108 题型: 编程题   语言: G++;GCC Description  给定六个正整数a,b,c,d ...

  10. javascript document.referrer 用法

    document对象的referrer属性,返回导航到当前网页的超链接所在网页的URL. 举例: 1. a.html文件内容如下: <a href="b.html">浏 ...