汇总如下:
using System; using System.Collections; using System.Linq; namespace SortDemo { public class MySort2 : IComparer { public int Compare(object x, object y) { return (int)y - (int)x; } } public class MySort3 : IComparer { int IComparer.Compare(object x, object y) { return ((new CaseInsensitiveComparer()).Compare(y,x)); } } class Program { static void Main(string[] args) { //方法1: int[] iArray1 = { 11, 2, 66, 33, 100, 55 }; Array.Sort(iArray1); Array.Reverse(iArray1); Console.WriteLine("-------1------"); foreach (var e in iArray1) { Console.WriteLine(e); } //方法2: Console.WriteLine("-------2------"); int[] iArray2 = { 11, 2, 66, 33, 100, 55 }; MySort2 mySort2 = new MySort2(); Array.Sort(iArray2, mySort2); foreach (var e in iArray2) { Console.WriteLine(e); } //方法2: Console.WriteLine("-------3-------"); int[] iArray3 = { 11, 2, 66, 33, 100, 55 }; MySort3 mySort3 = new MySort3(); Array.Sort(iArray3, mySort3); foreach (var e in iArray3) { Console.WriteLine(e); } //方法4: Console.WriteLine("--------4-------"); int[] iArray4= { 11, 2, 66, 33, 100, 55 }; var iA4 = iArray4.OrderByDescending(i => i).Select(i => i); foreach (var e in iA4) { Console.WriteLine(e); } //方法5: Console.WriteLine("--------5-------"); int[] iArray5 = { 11, 2, 66, 33, 100, 55 }; var iA5 = from e in iArray4 orderby e descending select e; foreach (var e in iA5) { Console.WriteLine(e); } } } }
标签:大法,Console,66,C#,-------,int,WriteLine,var,逆序 From: https://www.cnblogs.com/exesoft/p/16900359.html