Esempio n. 1
0
        // IComparable implementation.

        /*
         * int IComparable.CompareTo(object obj)
         * {
         *  Car temp = obj as Car;
         *  if (temp != null)
         *  {
         *      if (this.CarID > temp.CarID)
         *          return 1;
         *      if (this.CarID < temp.CarID)
         *          return -1;
         *      else
         *          return 0;
         *  }
         *  else
         *      throw new ArgumentException("Parameter is not a Car!");
         * }
         */

        // CompareTo method does exactly the same as above, just uses CompareTo method from CarID (an integer).
        //  Integers have a default CompareTo method, which is why this works.

        int IComparable.CompareTo(object obj)
        {
            if (obj is Car)
            {
                return(CarID.CompareTo((obj as Car).CarID));
            }
            else
            {
                throw new ArgumentException("Parameter is not a Car!");
            }
        }
Esempio n. 2
0
        int IComparable.CompareTo(object obj)
        {
            Car temp = obj as Car;

            if (temp != null)
            {
                return(CarID.CompareTo(temp.CarID));
            }
            else
            {
                throw new ArgumentException("Parameter is ot a Car");
            }
        }