C#数组去重和冒泡排序

数组去重

string[] x = { "aaa", "bbb", "aaa", "ccc", "bbb", "ddd", "ccc", "aaa", "bbb", "ddd" };
            
            List<string> y = new List<string>();
            foreach (string z in x)
            {
                if (!y.Contains(z))
                    y.Add(z);
            }
           
            foreach (string z in y)
            {
                Console.WriteLine(z); 
            }
            Console.ReadLine();

 冒泡排序

int[] z =new int[]{2,3,1,5,4};

 for(int i = 0;i<i.Lengt-1;i++){

for(int j = i+1;j<i.Length;j++){

if(z[i]>z[j]){

int f=a[i];

a[i]=a[j];

a[j]=f

}

}

}

for(int i=0;i<a.Length;i++){

Console.WriteLine(a[i]);

}
原文地址:https://www.cnblogs.com/skyhorseyk/p/7017431.html