C#基础——泛型
作者:互联网
泛型类
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>();
标签:C#,基础,classB,ClassA,泛型,new,classA,List 来源: https://www.cnblogs.com/LY-CS/p/13226216.html