public static void RandomSort<T>(this List<T> @this)
{
var random = new Random();
var newList = new List<T>();
foreach (var item in @this)
{
newList.Insert(random.Next(newList.Count), item);
}
for (int i = 0; i < @this.Count; i++)
{
@this[i] = newList[i];
}
}
由於使用的是this擴展
調用的時候只需要直接.
方法
listTest.RandomSort();