昨天有練習對數字陣列進行排序,《C#陣列Array排序》https://www.cnblogs.com/insus/p/10825174.html 其實一切都弄得很複雜,array已經有2個方法OrderBy和OrderByDescending: 參考下麵代碼演示: int[] ints = { 1 ...
昨天有練習對數字陣列進行排序,《C#陣列Array排序》https://www.cnblogs.com/insus/p/10825174.html
其實一切都弄得很複雜,array已經有2個方法OrderBy和OrderByDescending:
參考下麵代碼演示:
int[] ints = { 10, 45, 15, 39, 21, 26 }; foreach (var i in ints.OrderBy(g => g)) { System.Console.Write(i + " "); } Console.WriteLine(); var str = new string('-', 10); Console.Write(str); Console.WriteLine(); foreach (var i in ints.OrderByDescending(g => g)) { System.Console.Write(i + " "); } Console.WriteLine();Source Code
按Ctrl + F5運行控制台程式:
為了源碼與存檔,寫成一個類: