Example #1
0
        private static void DeligateSample()
        {
            Hat   myHat  = new Hat("cowboy", 7);
            TryOn theHat = myHat.TryOnHat;

            theHat("I tryon a" + myHat.HatType + " hat that was size" + myHat.HatSize);
            Hat mySecondHat = new Hat();
        }
Example #2
0
        private static void DelegateSample()
        {
            Hats  myHat  = new Hats("Cowboy", 7);
            TryOn theHat = myHat.TryOnHat;

            theHat("I tried on a " + myHat.HatType + "hat that was size" + myHat.HatSize);
            Hats mySecondHat = new Hats();  //calling second delegate
        }
Example #3
0
        static void DelegateSample()
        {
            Hats  myHat  = new Hats("Cowboy", 7);
            TryOn theHat = myHat.TryOnHat;

            theHat("I can not fit this size of " + myHat.HatType + "; It must be a size " +
                   myHat.HatSize);

            Hats mySecondHat = new Hats();
        }
Example #4
0
        //Delegate example (Advanced)
        private static void DelegateSample()
        {
            Hats  myHat  = new Hats("Cowboy", 7);
            TryOn theHat = myHat.TryOnHat;

            theHat("I tried on a " + myHat.HatType + "hat that was size " + myHat.HatSize);

            //Another version of the delegate, independent of the above example
            Hats mySecond = new Hats();
        }
Example #5
0
        static void MyLesson17Examples()
        {
            Lesson17 my17   = new Lesson17("Cowboy", 7);
            TryOn    theHat = my17.TryOnHat;

            theHat("I tried on a " + my17.HatType + "hat that was size" + my17.HatSize);

            Lesson17 myLesson17 = new Lesson17();
            Lesson17 myFav17    = new Lesson17("Trucker");

            Console.WriteLine(myFav17.MyResult);
            Console.WriteLine(myFav17.MyLambdaExample(6));
        }
Example #6
0
        static void MyLesson17Examples()
        {
            Lesson17 my17   = new Lesson17("Fedora", 8);
            TryOn    theHat = my17.TryOnHat;

            theHat("I tried on a " + my17.HatType + " hat that was a size "
                   + my17.HatSize);

            Lesson17 MyLesson17 = new Lesson17();

            Lesson17 myFav17 = new Lesson17("Skullcap");

            Console.WriteLine(myFav17.MyResult);
            Console.WriteLine(myFav17.MyLambdaExample(9));
        } // end method my lesson 17
        public delegate void TryOn(string Type);  //won't work in main

        public static void RunWeek4Classwork()
        {
            DelegateSample();

            EventSample();

            LambdaSample();

            void LambdaSample()
            {
                LambdaExamples myLamb = new LambdaExamples();

                //myLamb.MyLambdaOne(5);
                Console.WriteLine(myLamb.MyLambdaOne(5));


                LambdaExamples mySecond = new LambdaExamples(23);

                Console.WriteLine(mySecond.MyLambdaOne(mySecond.MyValue));
            }

            void DelegateSample()
            {
                Hats  myHat  = new Hats("Cowboy", 7); //old stuff
                TryOn theHat = myHat.TryOnHat;

                theHat("I tried on a " + myHat.HatType + " hat was size " + myHat.HatSize);

                Hats mySecond = new Hats();
            }

            void EventSample()
            {
                Coats  myCoat = new Coats();      //Instantiate the class
                string result = myCoat.MyResult;  //Get results from the property

                Console.WriteLine(result);
            }
        }
Example #8
0
 public void TryALargerHat(string type, int oldSize, TryOn another)
 {
     another("I tried on a " + type + " hat at size " + (oldSize + 1).ToString());
     //Note that ++oldSize and oldSize++ will produce different results
 }
Example #9
0
        public Hats()
        {
            TryOn myHat = TryOnHat;

            TryALargerHat("fedora", 7, myHat);
        }
Example #10
0
 public void TryALargerHat(string type, int oldSize, TryOn another)
 {
     another("I tried on a " + type + " hat at size " + (oldSize + 1).ToString());
 }