sharonshmuelfeldman
Joined: 29 Jul 2009 Posts: 8
|
Posted: Wed Aug 05, 2009 5:32 pm Post subject: using the ICOMPARE |
|
|
//1) put :
public class Car : IComparable
//2) in Car Class put :
public int CompareTo(object obj)
{
if (obj is Car) {
return this.Year.CompareTo((obj as Car).Year); // compare user names
}
throw new ArgumentException("Object is not a Car");
}
//3 use in parkinglot (replace old sort) :
Array.Sort(cars,0, Num_of_cars-1);//array+index+length
________
Parkwood |
|