我想实现在 an 中放入随机数的效果,IList
似乎我无法想到如何获取 的类型IList
,无论是 anint
还是decimal
等。我不能简单地Console.ReadLine()
将IList
.
public void RandomizeIList<T>(IList<T> list)
{
randomNum = new Random();
T typeRead = 0, typeReadSeed = 0;
String strRead = "", strReadSeed = "";
Console.WriteLine("How many {0}s do you want to randomly generate?", list.GetType());
T strRead = (list.GetType())Console.ReadLine();
Console.WriteLine("What's the limit of the randomly generated {0}s?", list.GetType());
Int32.TryParse(strReadSeed, out intReadSeed);
for (int i = 0; i < strRead; i++)
{
list[i] = randomNum.Next(intReadSeed);
}
}