开发者

How to Sort Typed List Collection

开发者 https://www.devze.com 2022-12-28 06:13 出处:网络
I have class like public class ProgressBars { public ProgressBars() { } private Int32 _ID; private string _Name;

I have class like

public class ProgressBars
{
    public ProgressBars()
    { }
    private Int32 _ID;
    private string _Name;
    public virtual Int32 ID {get { return _ID; } set { _ID = value; } }
    public virtual string Name { get { return _Name; } set { _Name = value; }}
}

here is List collection

List<ProgressBars> progress;
progress.Sort //I need to get sort here by 开发者_C百科Name

how can I sort this collection by Name?

Thanks


Provided that you can use LINQ

progress = progress.OrderBy(b => b.Name).ToList();


Related questions:

  • linq Order By for a List(Of myObjects)
  • Sorting a list using Lambda/Linq to objects


Implement Icomparable interface and ur done

public class ProgressBars : IComparable

{

    public ProgressBars()
    { }
    private Int32 _ID;
    private string _Name;
    public virtual Int32 ID { get { return _ID; } set { _ID = value; } }
    public virtual string Name { get { return _Name; } set { _Name = value; } }

    public int CompareTo(ProgressBars obj)
    {
        return _Name.CompareTo(obj.Name);
    }        
} 
0

精彩评论

暂无评论...
验证码 换一张
取 消