Beispiel #1
0
        public ArrayWorker(int n)
        {
            _a = new Worker[n];

            for (int i = 0; i < n / 2; i++)
            {
                _a[i] = new MonthWorker(i * 10100);
            }
            for (int i = n / 2; i < n; i++)
            {
                _a[i] = new HourlyWorker(i * 101);
            }
        }
Beispiel #2
0
        static void Main(string[] args)
        {
            // Test Worker, HourlyWorker, MonthWorker

            Worker[] workers = new Worker[10];
            int      k       = 0;

            workers[k++] = new MonthWorker("Kid", 30000);
            workers[k++] = new HourlyWorker("Cat", 3000);

            for (; k < workers.Length / 2; k++)
            {
                workers[k] = new HourlyWorker(101 * k);
            }
            for (; k < workers.Length; k++)
            {
                workers[k] = new MonthWorker(11000 * k);
            }

            for (int i = 0; i < workers.Length; i++)
            {
                Console.WriteLine(string.Format("{0} {1}", workers[i], workers[i].MonthSalary()));
            }

            Console.Write("\nArray sort test:\n");
            Array.Sort(workers);
            for (int i = 0; i < workers.Length; i++)
            {
                Console.WriteLine(string.Format("{0} {1}", workers[i], workers[i].MonthSalary()));
            }

            ArrayWorker aw = new ArrayWorker(10);


            Console.Write("\nForeach test:\n");
            foreach (Worker item in aw)
            {
                Console.WriteLine(string.Format("{0} {1}", item.ToString(), item.MonthSalary()));
            }

            //Console.Write(aw);

            return;
        }