比如我有个泛型类:class aaa<T>{}然后我想把这些实例化的类加入到List<T>里面去:aaa<int> a = new aaa<int>();aaa<double> b = new aaa<double>();aaa<string> c = new aaa<string>();我想把上面的3个实例都add到这个List<T> 里面去,这个该怎么加?因为 在实例化 List<aaa<int>> lit = new List<aaa<int>>()
这个地方需要要指定aaa这个泛型类的T的类型,但是我的这些T可能不一样,能加吗,
这个地方需要要指定aaa这个泛型类的T的类型,但是我的这些T可能不一样,能加吗,
using System.Collections.Generic;
using System.Linq;
using System.Text;namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
List<Base> list = new List<Base>();
list.Add(new A<int>());
}
} class Base { }; class A<T> : Base
{
public override string ToString()
{
return this.GetType().ToString();
}
}
}
没有什么隐患