一、这是一个实体类和一个比较器
class Cal
{
public string name;
public double price;
public Cal(string n,double p)
{
this.name = n;
this.price=p;
}
}
//这是个比较器
class NPriceComparer : IComparer<Cal>
{
//实现姓名升序
public int Compare(Cal x, Cal y)
{
return (x.price.CompareTo(y.price));
}
}
二、这是实用例子
List<Cal> resultlist = new List<Cal>();
for (int i = 0; i <10; i++)
{
Cal c = new Cal(i.toString(),9+i+1);
resultlist.Add(c);
}
resultlist.Sort(new NPriceComparer());