Пример #1
0
        //Lambda example
        private static void LambdaSample()
        {
            LambdaExamples myLamb = new LambdaExamples();

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

            LambdaExamples mySecond = new LambdaExamples(23);

            Console.WriteLine(mySecond.MyLambdaOne(mySecond.MyValue));
        }
Пример #2
0
        private static void LambdaSample()
        {
            LambdaExamples myLAmbda = new LambdaExamples();

            Console.WriteLine(myLAmbda.MyLambdaOne(5));
            Console.WriteLine(myLAmbda.MyLambdaOne(6));
            Console.WriteLine(myLAmbda.MyLambdaOne(7));
            Console.WriteLine(myLAmbda.MyLambdaOne(8));
            Console.WriteLine(myLAmbda.MyLambdaOne(9));
            Console.WriteLine(myLAmbda.MyLambdaOne(10));
        }
Пример #3
0
        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);
            }
        }
Пример #4
0
        static void LambdaExpressions()
        {
            var lambdaExamples = new LambdaExamples();

            var books          = new LambdaExpressions.Book();
            var bookRepository = new LambdaExpressions.BookRepository().GetBooks();

            var cheapBooks = bookRepository.FindAll(books.IsCheaperThanTenDollars);

            foreach (var book in cheapBooks)
            {
                Console.WriteLine(book.Title);
            }

            // This Lambda Expression is exactly the same as the above code
            var cheapBooksLambda = bookRepository.FindAll(book => book.Price < 10);

            foreach (var book in cheapBooksLambda)
            {
                Console.WriteLine(book.Title);
            }
        }
Пример #5
0
        private static void LambdaSample()
        {
            LambdaExamples myLamb = new LambdaExamples();

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