int[] arr = { 8, 10, 5, 6, 45, 676, 20, 35,8 };
List<int> list = new List<int>();//声明了一个list,长度可变数组
foreach (int nums in arr)
{
list.Add(nums);
}
list.Sort();//升序
foreach (int value in list)
{
Console.Write(value+",");
}
Console.WriteLine();
list.Reverse();//将list中的元素反转(先list.Sort(),然后list.Reverse()就可以达到降序的目的)
foreach (int value in list)
{
Console.Write(value+",");
} |