泛型类
class Program
{
static void Main(string[] args)
{
//声明泛型类
ClassA<int> classA = new ClassA<int>();
classA.a = 1;
classA.b = 2;
Console.WriteLine("a:{0},b:{1}",classA.a,classA.b);
ClassA<string> classB = new ClassA<string>();
classB.a = "A";
classB.b = "B";
Console.WriteLine("a:{0},b:{1}", classB.a, classB.b);
Console.Read();
}
}
class ClassA<T>
{
public T a { get; set; }
public T b { get; set; }
}
泛型集合
List<T> mList = new List<T>();
T为列表中元素类型,现在以string类型作为例子
List<string> mList = new List<string>();