1 using System;
2 using System.Collections.Generic;
3 using System.Collections;
4
5
6 class a
7 {
8 public void test<T>(List<T> a,List<T> b)//定义泛型方法,和两个泛型列表类型的参数
9 {
10 Console.WriteLine(a);
11 Console.WriteLine(b);
12 Console.WriteLine();
13 Console.WriteLine("泛型参数a的值:");
14 foreach (var i in a) {//用foreach循环出泛型列表a的值
15 Console.Write(i+"\n");
16 }
17 Console.WriteLine("\n泛型参数b的值:");
18 foreach (var i in b) {//用foreach循环出泛型列表a的值
19 Console.Write(i+"\n");
20 }
21 }
22 }
23 class b
24 {
25 public static void Main()
26 {
27 List<int> l1 = new List<int>();//实例化泛型列表,并加入两个成员
28 l1.Add(123);
29 l1.Add(666);
30
31 List<int> l2 = new List<int>();//实例化另泛型列表,并加入两个成员
32 l2.Add(112);
33 l2.Add(33);
34 a A = new a();//实例化类a
35 A.test<int>(l1,l2);//调用类的泛型方法test(),并向其两个泛型列表类型的参数赋值
36
37 //Console.WriteLine(A.test<int>(l1,l2));
38 Console.ReadKey();
39 }
40 }