using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace test3
{
class Program
{
static void Main(string[] args)
{
int[] arr = { 8, 10, 5, 6, 45, 676, 20, 35 };
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+",");
}
Console.ReadKey();
}
}
}
|