我有这门课:
public class Myclass
{
public int id;
public string name;
}
Run Code Online (Sandbox Code Playgroud)
和收藏:
Collection<Myclass> myCollection = new Collection<Myclass>();
Run Code Online (Sandbox Code Playgroud)
我怎么可以通过id对这个集合进行排序????
使你的类implment IComparable,并定义
int CompareTo(MyClass other)
{
return Id.compareTo(other.Id);
}
Run Code Online (Sandbox Code Playgroud)
然后可以使用任何标准排序函数.