示例#1
0
 public Warehouse()
 {
     rental_price = 1000;
     num          = 5;
     array        = new Consignment[num];
     for (int i = 0; i < num; i++)
     {
         Random rand = new Random();
         array[i] = new Consignment(rand.Next(900), rand.Next(867), "potato", "Egypt", rand.Next(3), 2019, rand.Next(12), rand.Next(30));
     }
 }
示例#2
0
        public int CompareTo(object obj)
        {
            if (obj == null)
            {
                return(1);
            }
            Consignment c = obj as Consignment;

            if (c as Consignment == null)
            {
                return(1);
            }
            return(this.price - c.price);
        }
示例#3
0
        static void Main(string[] args)
        {
            Console.Write("Vegetable v: ");
            Vegetable v = new Vegetable("Carrot", "France", 2);

            v.print();
            Console.Write("\nCopy of v: ");
            Vegetable v_copy = v;

            v_copy.print();

            Consignment c1 = new Consignment(250, 10, "Cabbage", "USA", 1, 2019, 12, 11);
            Consignment c2 = new Consignment(350, 45, "Cabbage", "USA", 1, 2019, 12, 13);

            Console.WriteLine("\n\nC1: " + c1.ToString() + "\nC2: " + c2.ToString());
            Console.Write("Enter a new price for c2: ");
            c2.Price = Convert.ToInt32(Console.ReadLine());
            Console.WriteLine("c1>c2: " + (c1 > c2).ToString());

            Consignment c3 = new Consignment();

            Console.Write("\nDefault Consignment c3: " + c3.ToString());
            c3 = c1 + c2;
            Console.Write("\nc3=c1+c2: ");
            c3.print();

            Warehouse Warehouse = new Warehouse();

            Console.Write("\n\nIndexator: Enter a number(<5)\n");
            int i = Convert.ToInt32(Console.ReadLine());

            Console.WriteLine("Warehouse[" + i.ToString() + "] : " + Warehouse[i].ToString());

            Vegetable[] arr = new Vegetable[2];
            arr[0] = v;
            arr[1] = c1;
            Console.Write("\n\narr[0] is Vegetable, arr[1] is Consignment\n");
            Console.WriteLine("Virtual function:");
            Console.Write("arr[0]:"); arr[0].print();
            Console.Write("\narr[1]:"); arr[1].print();
            Console.WriteLine("\nNon virtual function function:");
            Console.Write("arr[0]:"); arr[0].shortInfo();
            Console.Write("\narr[1]:"); arr[1].shortInfo();

            Console.ReadLine();
        }