// Start a program where user has to select which option to run
        // string key - option that user has to select
        // WhoAmI function - writes on a console Name of the object and EarSize
        // SpeakTo function - just an example how ".this" operation works in C#
        // Swap - do swap of two objects
        // HearMessage - presents a mesage from an object to another Elephant object
        public static void StartElephantProgram(Elephant first, Elephant second)
        {
            string key;

            Console.WriteLine("Press 1 for Lloyd, 2 for Lucinda, 3 to swap");
            key = Console.ReadLine();

            if (key == "1")
            {
                first.WhoAmI();
            }

            else if (key == "2")
            {
                second.WhoAmI();
            }
            else if (key == "4")
            {
                first.SpeakTo(second, "Hi " + second.Name);
            }
            else
            {
                first.Swap(first, second);
            }
        }
Пример #2
0
        static void Main(string[] args)
        {
            Elephant Lloid = new Elephant {
                Name = "Lloyd", EarSize = 40
            };
            Elephant Lucinda = new Elephant {
                Name = "Lucinda", EarSize = 80
            };

            Lloid.HearMessage("Hi", Lucinda);
            Lucinda.SpeakTo(Lloid, "Hi ");

            int howLong = 0;

            while (howLong == 0)
            {
                Elephant BackToNormal = new Elephant {
                    Name = "0", EarSize = 0
                };


                Elephant.StartElephantProgram(Lloid, Lucinda);
                Console.WriteLine("Do you want to continiue ?  1 = no, 0 = yes");
                string howLongSttring = Console.ReadLine();
                howLong = Int32.Parse(howLongSttring);
            }
        }