泛型: 广泛的类型 一般用于传递类型的
泛型的命名规范:以T开头的单词命名,
<> 中间类型就是传入泛型
<int> 整形的泛型
<T> 泛型类型
List<string> list = new List<string>();
Dictionary<int, int> dic = new Dictionary<int, int>();
Dictionary<string, string> dic1 = new Dictionary<string, string>();
泛型使用在方法定义上,
调用泛型方法 通过<>将类型的实参进行传递,
对应的位置泛型形参就是这个类型
Test<int>(1);// T 传递的是int类型 此次参数必须是int类型
Test<string>("a");// T传递的string 此次参数必须是字符串类型
// Test(1); 泛型方法调用时候简化写法 系统自动推断类型
// Test("a");
2 调用带两个泛型参数的方法 Test1 传递的类型是一个
Test1<int>(10, new int[] { 10 });
3 调用Test2方法 传入两个泛型类型 参数个数是2个
Test2<int, string>(10, "a");
Test2<int, int>(10, 10);