1)宣告乙個類
/// /// 人物類
///
public class person
}
2)宣告乙個繼承了介面icomparer的類
/// /// 比較人物類例項大小,實現介面icomparer
///
public class personcomparer : icomparer
return 0;
}}
3)main函式,建立乙個list,並使用剛建立的personcomparer類中的規則對list進行排序
static void main(string args)
); a.add(new person() );
a.add(new person() );
a.add(new person() );
a.add(new person() );
a.add(new person() );
//輸出a中全部元素
console.writeline("排序前");
foreach (var v in a)
console.writeline("-");
//對a進行排序
a.sort(new personcomparer());
//輸出a中全部元素
console.writeline("排序後");
foreach (var v in a)
console.writeline("-");
console.readline();
}
c 自定義排序
class program console.writeline console.writeline source tolist value var list arr.tolist for int i 0 i 10 i console.writeline console.writeline sourc...
C 自定義排序
include include include using namespace std bool compare1 const int a,const int b bool compare2 const int a,const int b bool compare3 const int a,cons...
C 自定義List類
如下 using system using system.collections.generic using system.linq using system.text namespace myarraylist public myarraylist int capacity 索引器 public ...