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);
}
}
精彩评论