using System;
using System.Collections;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
int temp = 0;
int[] intArr = new int[100];
ArrayList myList = new ArrayList();
Random rnd = new Random();
while (myList.Count < 100)
{
int num = rnd.Next(1, 101);
if (!myList.Contains(num)) // 这句是关键
myList.Add(num);
}
//
// 转换为整形数组
for (int i = 0; i < 100; i++)
intArr[i] = (int)myList[i];
//
// 排序
for (int i = 0; i < intArr.Length-1; i++)
{
for (int j = 0; j < intArr.Length-1; j++)
{
if(intArr[j] > intArr[j+1])
{
temp = intArr[j + 1];
intArr[j + 1] = intArr[j];
intArr[j] = temp;
}
}
}
//
// 输出
for (int i = 0; i < intArr.Length; i++)
{
Console.WriteLine(intArr[i].ToString());
}
Console.Read();
}
}
}
using System.Collections;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
int temp = 0;
int[] intArr = new int[100];
ArrayList myList = new ArrayList();
Random rnd = new Random();
while (myList.Count < 100)
{
int num = rnd.Next(1, 101);
if (!myList.Contains(num)) // 这句是关键
myList.Add(num);
}
//
// 转换为整形数组
for (int i = 0; i < 100; i++)
intArr[i] = (int)myList[i];
//
// 排序
for (int i = 0; i < intArr.Length-1; i++)
{
for (int j = 0; j < intArr.Length-1; j++)
{
if(intArr[j] > intArr[j+1])
{
temp = intArr[j + 1];
intArr[j + 1] = intArr[j];
intArr[j] = temp;
}
}
}
//
// 输出
for (int i = 0; i < intArr.Length; i++)
{
Console.WriteLine(intArr[i].ToString());
}
Console.Read();
}
}
}
欢迎转载,转载请注明出处:http://www.cnblogs.com/Tonyyang/