我需要解释一下关于泛型类类型的问题。
我们以以下愚蠢的方法为例:
public List<> RandomList() //Note that the Compiler yells at you for not giving a type parameter
{
var RandObj = new Random();
var myint = RandObj.Next(1,3);
switch(myint)
{
case 1: var StringList = new List<string>{ "Test" };
return StringList;
case 2: var IntList = new List<int>{ 1,2,3,4 };
return IntList;
}
}
有没有办法让这个函数起作用?我想知道是否有一种方法可以设置它,以便我可以说:“这个函数返回一个列表。我不确定它将返回什么类型的列表,但它肯定是一个列表。”