Ejemplo n.º 1
0
        public int Compare(object?x, object?y)
        {
            GeometricObject geo1 = x as GeometricObject;
            GeometricObject geo2 = y as GeometricObject;

            if (geo1 != null && geo2 != null)
            {
                return(Bigger(geo1, geo2));
            }
            else
            {
                throw new InvalidCastException();
            }
        }
Ejemplo n.º 2
0
 public static int Bigger(GeometricObject x, GeometricObject y)
 {
     if (x.GetValue() > y.GetValue())
     {
         return(1);
     }
     else if (x.GetValue() < y.GetValue())
     {
         return(-1);
     }
     else
     {
         return(0);
     }
 }
Ejemplo n.º 3
0
        static void Main(string[] args)
        {
            GeometricObject[] arr = new GeometricObject[3];
            arr[0] = new GeometricObject("hallo");
            arr[1] = new Circle("hh");
            arr[2] = new Rectangle("ffff");

            foreach (GeometricObject geo in arr)
            {
                geo.Start();
            }

            Console.WriteLine("------------------------------");

            //GeometricObjectCompare a = new GeometricObjectCompare();
            //Array.Sort(arr, a);

            Array.Sort(arr, new GeometricObjectCompare());

            foreach (GeometricObject geo in arr)
            {
                geo.Start();
            }
        }