【转载】#324 - A Generic Class Can Have More than One Type Parameter
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的更多相关文章
- [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 ...
- 【转载】#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) ...
- 关于C#你应该知道的2000件事
原文 关于C#你应该知道的2000件事 下面列出了迄今为止你应该了解的关于C#博客的2000件事的所有帖子. 帖子总数= 1,219 大会 #11 -检查IL使用程序Ildasm.exe d #179 ...
- 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 ...
- cs108 03 ( 调试, java通用性)
Debuger Great questions These questions will solve most bugs: what method shows the symptom ? what l ...
- C# Generic(转载)
型(generic)是C#语言2.0和通用语言运行时(CLR)的一个新特性.泛型为.NET框架引入了类型参数(type parameters)的概念.类型参数使得设计类和方法时,不必确定一个或多个具体 ...
- C#:泛型(Generic)
前言: 此系列都为个人对C#的回顾,属于个人理解,新司机可参考.求老司机指点.如果有什么问题或不同见解,欢迎大家与我沟通! 目录: 泛型是什么 泛型的好处及用途 如何声明使用泛型 泛型类 泛型方法 ...
- 转载:《TypeScript 中文入门教程》 9、泛型
版权 文章转载自:https://github.com/zhongsp 建议您直接跳转到上面的网址查看最新版本. 介绍 软件工程中,我们不仅要创建一致的定义良好的API,同时也要考虑可重用性. 组件不 ...
- 转载:C#中的泛型
泛型(generic)是C#语言2.0和通用语言运行时(CLR)的一个新特性.泛型为.NET框架引入了类型参数(type parameters)的概念.类型参数使得设计类和方法时,不必确定一个或多个具 ...
随机推荐
- 搭建 flask 应用
参考文档:http://docs.jinkan.org/docs/flask/quickstart.html#a-minimal-application 1.使用Pycharm创建Flask应用 fr ...
- vue混入(mixins)
混入(mixins)是一种分发vue组件中可复用功能的非常灵活的方式.混入对象可以包含任意组件选项. 当组件使用混入对象时,所以混入对象的选项将被混入该组件本身选项,当组件和混入对象含有同名选项时,这 ...
- Python Pandas Merge, join and concatenate
Pandas提供了基于 series, DataFrame 和panel对象集合的连接/合并操作. Concatenating objects 先来看例子: from pandas import Se ...
- ubuntu hadoop集群 master免密码登陆到slave节点
1. 在master节点上安装ssh client,在slave节点上安装ssh server sudo apt-get install openssh-client sudo apt-get ins ...
- TCP Nagle算法以及延迟确认(即延迟回复ACK)的学习
TCP/IP协议中,无论发送多少数据,总是要在数据前面加上协议头,同时,对方接收到数据,也需要发送ACK表示确认.为了尽可能的利用网络带宽,TCP总是希望尽可能的发送足够大的数据. (一个连TCP接会 ...
- 解决ajax提交中文数据乱码
function replaceWord(date,wordurl){ $.ajax({ url : 'wordReplace', ...
- input类型为file改变默认按钮样式
改变 input file 样式(input 文件域)是很多前端朋友经常遇到的头疼问题,今天推荐两种改变 input file 样式的两种常用方法: 方法一: <input type=&quo ...
- CAD安装失败怎样卸载CAD 2010?错误提示某些产品无法安装
AUTODESK系列软件着实令人头疼,安装失败之后不能完全卸载!!!(比如maya,cad,3dsmax等).有时手动删除注册表重装之后还是会出现各种问题,每个版本的C++Runtime和.NET f ...
- Oracle SQL Tuning Advisor 测试
如果面对一个需要优化的SQL语句,没有很好的想法,可以先试试Oracle的SQL Tuning Advisor. SQL> select * from v$version; BANNER --- ...
- git跟svn 服务端对比
Git已经火了很久,简单的使用也没有问题,但有几个问题一直以来都没有搞清楚:git跟svn有哪些异同,两者相互的优劣是什么,git的分布式怎么理解,为什么有离线提交,,,自己动手,分别看一下服务端跟客 ...