How to sort List<Point>

This question already has an answer here:

  • How to Sort a List<T> by a property in the object 19 answers

  • LINQ:

    pointsOfList = pointsOfList.OrderByDescending(p => p.X).ToList();
    

    pointsOfList.OrderBy(p=>p.x).ThenBy(p=>p.y)
    

    这个简单的控制台程序可以:

    class Program
    {
        static void Main(string[] args)
        {    
            List<Points> pointsOfList =  new List<Points>(){
                new Points() { x = 9, y = 3},
                new Points() { x = 4, y = 2},
                new Points() { x = 1, y = 1}
            };
    
            foreach (var points in pointsOfList.OrderBy(p => p.x))
            {
                Console.WriteLine(points.ToString());
            }
    
            Console.ReadKey();
        }
    }
    
    class Points
    {
        public int x { get; set; }
        public int y { get; set; }
    
        public override string ToString()
        {
            return string.Format("({0}, {1})", x, y);
        }
    }
    
    链接地址: http://www.djcxy.com/p/70932.html

    上一篇: 如何通过整数属性对类列表进行排序?

    下一篇: 如何对List <Point>进行排序