bubble sort一般是10000 ticks(10ms) 而linq sort却是70000 (70ms)左右 using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.IO; namespace BubbleSort { class Program { static void Main(string[] args) { BubbleMan mb = new BubbleMan("data.txt"); DateTime temp1dt1 = DateTime.Now; int[] temp1=mb.BubbleSort(); DateTime temp1dt2 = DateTime.Now; long xxx = temp1dt2.Ticks - temp1dt1.Ticks; DateTime temp2dt1 = DateTime.Now; int[] temp = mb.LinqSort(); DateTime temp2dt2 = DateTime.Now; long yyy = temp2dt2.Ticks - temp2dt1.Ticks; } } class BubbleMan { protected int[] IntArray; //protected int[] current; public BubbleMan(string file) { if (File.Exists(file)) { string str = File.ReadAllText(file,Encoding.Unicode); str = str.Replace("/r/n", " "); string[] temp = str.Split(' '); IntArray = Array.ConvertAll(temp, new Converter<string, int>(StrToInt)); } } public static int StrToInt(string str) { return int.Parse(str); } public int[] BubbleSort() { if (!IntArray.Length.Equals(0)) { for (int i = 0; i < IntArray.Length; i++) { for (int j = IntArray.Length-1; j >i; j--) { if (IntArray[i] < IntArray[j]) { int temp = IntArray[j]; IntArray[j] = IntArray[i]; IntArray[i] = temp; } } } } return IntArray; } public int[] LinqSort() { //int[] result=new int[IntArray.Length]; List<int> result = new List<int>(); var temp = from x in IntArray orderby x select x; foreach (int t in temp) { result.Add(t); } return result.ToArray(); } } }