我正在尝试创建一个扩展方法,可以对泛型列表集合进行随机排序,而不考虑其类型。但是我不确定在<..>之间应该放什么参数。我应该放object还是Type?我希望能够在任何List集合上使用此方法。
谢谢!
谢谢!
public static void Shuffle(this List<???????> source)
{
Random rnd = new Random();
for (int i = 0; i < source.Count; i++)
{
int index = rnd.Next(0, source.Count);
object o = source[0];
source.RemoveAt(0);
source.Insert(index, o);
}
}
IList<T>
会更通用。 - John SaundersIList<T>
有Insert
方法。哪个类实现了IList<T>
但没有实现Insert
方法? - John Saunders