using System; using System.Collections.Generic; using System.Linq; using System.Text; //using System.Drawing; namespace LambdaForSort { struct Point { public int X, Y; public Point(int X, int Y) { this.X = X; this.Y = Y; } } class Program { static void Main(string[] args) { List Pts = new List(); Random R = new Random(0); const int N = 8; Pts.Add(new Point(100, 101)); for (int i = 0; i < 16; i++) { Pts.Add(new Point(R.Next(N), R.Next(N))); } Pts.Add(new Point(100, 99)); Console.Write("Orignal:"); foreach (Point P in Pts) { Console.Write("[{0},{1}] ", P.X, P.Y); } Console.WriteLine(); Pts.Sort((P1, P2) => { if (P1.X > P2.X) return 1; if (P1.X < P2.X) return -1; if (P1.Y > P2.Y) return 1; if (P1.Y < P2.Y) return -1; return 0; }); Console.Write("Sorted:"); foreach (Point P in Pts) { Console.Write("[{0},{1}] ", P.X, P.Y); } return; } } }