1.泛型具有更好的性能。
ArrayList test1 = new ArrayList();
test1.Add(1);
test1.Add("1");
test1.Add(1.45);
List<int> test2=new List<int>();
test2.Add(1);
test2.Add(2);
test2.Add(3);
使用ArrayList,每次添加都是增加的对象,需要对值类型进行装箱操作;第二种写法不需要进行装箱操作
2.类型安全
使用泛型后,增加的元素都是指定的数据类型,因此我们很清除每个元素的类型,而ArrayList就不行
3.泛型能够更好地重用二进制代码
4.default关键字的使用
5.泛型约束
接口约束:
其他约束:
6.泛型类可以派生自泛型基类
public class Base<T>
{
}
public class Implente2<T>:Base<T>
{
}
public class Implente3<T> : Base<int>
{
}
public class Implente1 : Base<int>
{
}
7.泛型类中的静态成员,静态成员属于类,不属于具体实例,
8.泛型接口
。。。不大懂
9.抗变和协变
在.net4之前,泛型接口是不变的。在.net中参数类型是协变的,方法的返回类型是抗变的,
10.泛型接口的协变和抗变
。。。
11.泛型结构
于类相似,结构也可以是泛型的,知识没有继承特性
可空类型的写法
可空类型和非可空类型的转换
12.泛型方法
。。。。
13.带约束的泛型
。。。。。
14.带委托的泛型
。。。。