对生成的数组排序,需要支持升序、降序两种顺序
using System;
using System.Collections.Generic;
class Program
{
static void Main(string[] args)
{
Random random = new Random();
HashSet<int> set = new HashSet<int>();
while (set.Count < 100)
{
int num = random.Next(1, 101);
set.Add(num);
}
int[] array = new int[100];
set.CopyTo(array);
Console.WriteLine("升序排序:");
Array.Sort(array);
foreach (int num in array)
{
Console.Write(num + " ");
}
Console.WriteLine("\n降序排序:");
Array.Reverse(array);
foreach (int num in array)
{
Console.Write(num + " ");
}
}
}
标签:set,Console,C#,int,num,100,array
From: https://blog.csdn.net/fishandfishand/article/details/140116778