c# 中 List能对T对象排序的方法

c#的List<T>默认能够对基本类型排序,比如int, string, 但是对于用户自定义的对象排序则需要对代码进行少许改动,方法为:
public class StringValuePair: IComparable <StringValuePair> { public StrName; double Value; //default sort order is from small to big public int CompareTo(StringValuePair svp) { return this.Value.CompareTo(svp.Value); } }
 
Then for List<StringValuePair> list, we can call list.Sort() to sort the objects.

你可能感兴趣的:(String,list,C#,Class)