C# List 随机排序方法
public List<T> RandomSortList<T>(List<T> ListT) { Random random = new Random(); List<T> newList = new List<T>(); foreach (T item in ListT) { newList.Insert(random.Next(newList.Count + 1), item); } return newList; }
使用方法
List<int> list = new List<int>(); for (int i = 0; i < 10; i++) { list.Add(i); } list = RandomSortList<int>(list); foreach (var item in list) { Response.Write(item + "<br>"); }