How to sort a list by a specific property in .NET 2.0?

This question already has an answer here:

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

  • Check Sort method, that takes Comparison<T> . Avaliable from .NET 2.0

    var list = new List<Point>{ /* populate list */ };
    
    list.Sort(Comparison);
    
    
    public int Comparison (Point a, Point b)
    {
        //do logic comparison with a and b
        return -1;
    }
    

    你需要使用一个委托,几乎是一个单一的:)

    list.Sort(delegate(Point p1, Point p2){
            return p1.X.CompareTo(p2.X);
    });
    
    链接地址: http://www.djcxy.com/p/70936.html

    上一篇: C#:自定义属性的排序列表

    下一篇: 如何按.NET 2.0中的特定属性对列表进行排序?