public int CompareTo(object obj)
 {
     if (obj is Block3D)
     {
         Block3D other = (Block3D)obj;
         return(Rectangle.CompareTo(other.Rectangle));
     }
     return(1);
 }
        static void Main(string[] args)
        {
            Random rand = new Random();

            Block3D[] blocks = new Block3D[rand.Next(5, 10)];
            for (int i = 0; i < blocks.Length; i++)
            {
                blocks[i] = new Block3D(rand.Next(1, 20), new Rectangle(rand.Next(3, 30), rand.Next(3, 30)));
            }
            Array.Sort(blocks);
            Array.ForEach(blocks, (x) => Console.WriteLine(x));
        }
Beispiel #3
0
        static void Main(string[] args)
        {
            Random r = new Random();

            Block3D[] blocks = new Block3D[15];
            for (int i = 0; i < 15; i++)
            {
                blocks[i] = new Block3D(r.Next(1, 15), r.Next(1, 15), r.Next(1, 15));
                Console.WriteLine(blocks[i]);
            }
            Console.WriteLine("\nSorted:\n");
            Array.Sort(blocks);
            foreach (var block in blocks)
            {
                Console.WriteLine(block);
            }
        }
Beispiel #4
0
        static void Main(string[] args)
        {
            Random rnd = new Random();

            Block3D[] blocks = new Block3D[10];
            for (int i = 0; i < 10; ++i)
            {
                blocks[i] = new Block3D(rnd.NextDouble() * 10, rnd.NextDouble() * 10, rnd.NextDouble() * 10);
            }
            for (int i = 0; i < 10; ++i)
            {
                Console.WriteLine(blocks[i].ToString());
            }
            Console.WriteLine();
            Console.WriteLine("Sorted array:");
            Array.Sort(blocks);
            for (int i = 0; i < 10; ++i)
            {
                Console.WriteLine(blocks[i].ToString());
            }
        }