我喜欢上课
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; }}
}
这里是List collection
List<ProgressBars> progress;
progress.Sort //I need to get sort here by Name
如何按名称对此集合进行排序?
由于
答案 0 :(得分:6)
前提是您可以使用LINQ
progress = progress.OrderBy(b => b.Name).ToList();
答案 1 :(得分:2)
答案 2 :(得分:1)
实施Icomparable接口并完成
公共类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);
}
}