1、List打乱顺序代码
private List<T> RandomSort<T>(List<T> list) {
var random = new Random();
var newList = new List<T>();
foreach (var item in list) {
newList.Insert(random.Next(newList.Count), item);
}
return newList;
}
2、List顺序反转代码
using System;
using System.Collections.Generic;
public class Demo {
public static void Main(String[] args) {
List<int> list = new List<int>();
list.Add(5);
list.Add(10);
list.Add(20);
list.Add(50);
list.Add(100);
Console.WriteLine("Enumerator iterates through the list elements...");
List<int>.Enumerator demoEnum = list.GetEnumerator();
while (demoEnum.MoveNext()) {
int res = demoEnum.Current;
Console.WriteLine(res);
}
list.Reverse();
Console.WriteLine("Elements in List...Reversed");
foreach (int i in list) {
Console.WriteLine(i);
}
}
}