public int Compare(Car x, Car y)
  {
     return x.Price -y.Price;
  }
SortedList<String,Car> list=new SortedList<string,Car>();
list.Add(car1.CarBrand, car1);.....
list.Sort(new Comparison<Car>(Compare));

解决方案 »

  1.   

    Sortedlist 默认按键排序的键值对集合
    public int CompareTo(IComparable comp)
        {
            Car  c= (Car)comp;
            if (this.CarCost> c.CarCost)
                return 1;
            else if (this.CarCost== c.CarCost)
                return 0;
            else
                return -1;
        }
      

  2.   

    1楼的大哥你可能没试过,SortedList对象是没有Sort()方法的
    2楼的大哥虽然很谢谢你,但是没有用,你写的代码应该是在Car类里写的吧,但是用不了啊
      

  3.   

    呵呵,不好意思,很少用这个类,刚看了下果然是没有
    这样试试:
    SortedList<String,Car> list=new SortedList<string,Car>(new Sort());
        public class Sort :IComparer
        {        #region IComparer 成员        public int Compare(object x, object y)
            {
                Car carX = x as Car;
                Car carY = y as Car;
                return carX.CarCost - carY.CarCost;
            }        #endregion
        }