Example #1
0
        static void Main(string[] args)
        {
            Programmer        programer     = new Programmer();
            Builder           builder       = new Builder();
            List <IDeveloper> arrDevelopers = new List <IDeveloper>();

            Console.WriteLine("Adding 2 programmers: ");
            for (int i = 0; i < 2; i++)
            {
                programer.Create(arrDevelopers);
            }
            Console.WriteLine("Adding 2 builders: ");
            for (int i = 0; i < 2; i++)
            {
                builder.Create(arrDevelopers);
            }
            foreach (var item in arrDevelopers)
            {
                Console.WriteLine(item);
            }
            programer.Destroy(arrDevelopers);
            Output(arrDevelopers);
            builder.Destroy(arrDevelopers);
            Console.WriteLine("After Destroy is called: ");
            Output(arrDevelopers);

            var sortedList = string.Join(",", arrDevelopers.OrderBy(item => item.Tool));

            Console.WriteLine($"Ordered by ASC: {sortedList}\n");
        }
Example #2
0
        static void Main(string[] args)
        {
            //task 1

            List <IDeveloper> devs = new List <IDeveloper>();

            Console.WriteLine("how many people you want to write info for ?");
            int count = Convert.ToInt32(Console.ReadLine());

            for (int i = 1; i < count + 1; i++)
            {
                Console.WriteLine("type 1 to procces person {0} as Programmer, type 2 to process person {0} as Builder", i);
                int type = 0;

                try
                {
                    type = Convert.ToInt32(Console.ReadLine());
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }

                if (type == 1)
                {
                    IDeveloper unID = new Programmer();
                    unID.Create();
                    devs.Add(unID);
                }
                else if (type == 2)
                {
                    IDeveloper unID = new builder();
                    unID.Create();
                    devs.Add(unID);
                }
                else
                {
                    Console.WriteLine("{0} is not a valid type", type);
                }
            }

            devs.Sort();

            foreach (IDeveloper i in devs)
            {
                Console.WriteLine(i);
            }



            //task 2

            Dictionary <int, string> dict = new Dictionary <int, string>();
            int countDict = 7;

            for (int i = 0; i < countDict; i++)
            {
                Console.WriteLine("Please write your name, person {0}", i + 1);
                string val = Console.ReadLine();
                dict.Add(i + 1, val);
            }

            Console.WriteLine("enter id of the person you need, there are {0} people", countDict);

search:
            try
            {
                int unid = Convert.ToInt32(Console.ReadLine());

                if (unid > countDict)
                {
                    Console.WriteLine("{0} out of range {1}", unid, countDict);
                }
                else
                {
                    Console.WriteLine("{0} person is {1}", unid, dict[unid]);
                }
            }
            catch (FormatException)
            {
                Console.WriteLine("not a valid input type");
                goto search;
            }
        }