C# List 倒序和随机排序

void Main()
{
	var list = new List<MusicEntity>();
	for (int i = 0; i < 20; i++)
	{
		list.Add(new MusicEntity
		{
			Id = i,
			Path = new Random().Next(9999) + ";ljk;lkj",
			TotalTime = new Random().Next(9999)
		});
	}
	foreach (var element in list)
	{
		Console.WriteLine(element.Id);
	}
	Console.WriteLine("倒序===============================");
	list.Reverse();//倒序
	foreach (var element in list)
	{
		Console.WriteLine(element.Id);
	}
	Console.WriteLine("随机===============================");
	list = list.OrderBy(x => Guid.NewGuid()).ToList();//随机
	foreach (var element in list)
	{
		Console.WriteLine(element.Id);
	}
}
public class MusicEntity
{
	public long Id { get; set; }
	public string Path { get; set; }
	public int TotalTime { get; set; }
}

 

posted @ 2022-07-28 16:18  chenjingchun  阅读(1680)  评论(0编辑  收藏  举报