예제 #1
0
        static void Main(string[] args)
        {
            //Definition Of Anonymous Delegate
            GreetingDelegate obj = delegate(string name)
            {
                return("Hello" + name + "Godd Morning");
            };

            //Definition of Anonymous Delegate
            Addition_Delegate obj1 = delegate(int x, int y, int z)
            {
                return(x + y + z);
            };

            //Definition Of Anonymous Delegate
            Subtration_Delegate obj2 = delegate(int x, int y)
            {
                return(x - y);
            };

            //Instantiation of Delegates
            string str        = obj.Invoke("Girls");
            int    add_reault = obj1.Invoke(4, 7, 9);
            int    sub_result = obj2.Invoke(20, 10);

            //print Value Of Results
            Console.WriteLine("this Is String : {0} ", str);
            Console.WriteLine("This IS Addition Result : {0} ", add_reault);
            Console.WriteLine("This is Subtraction Result : {0} ", sub_result);
            Console.ReadKey();
        }
예제 #2
0
        static void Main(string[] args)
        {
            GreetingDelegate obj = (name) =>
            {
                return("hello " + name + " Very Good Morning");
            };
            string str = obj.Invoke("anil");

            Console.WriteLine(str);
            Console.ReadLine();
        }
예제 #3
0
        /* public static string Greetings(string name)
         * {
         *   return "Hello" + name + "good morning";
         * } */
        static void Main(string[] args)
        {
            GreetingDelegate obj = delegate(string name)  //new GreetingDelegate(Greetings);
            {
                return("Hello" + name + "good morning");
            };
            string str = obj.Invoke("Jeetu");

            Console.WriteLine(str);
            Console.ReadLine();
        }
예제 #4
0
        static void Main(string[] args)
        {
            GreetingDelegate obj = delegate(string name)
            {
                return("Hello " + name + ", Good Morning");
            };

            var str = obj.Invoke("eci");

            Console.WriteLine(str);
            Console.WriteLine("Hello World!");
        }
예제 #5
0
        //public static string Greetings(string value)
        //{
        //	return "the " + value + " Manager is very strict";

        //}
        static void Main(string[] args)
        {
            //GreetingDelegate obje = new GreetingDelegate(Greetings);
            GreetingDelegate obje = delegate(string value)
            {
                return("the " + value + " Manager is very strict");
            };
            string str = obje.Invoke("BANK");

            Console.WriteLine(str);
            Console.ReadLine();
        }
예제 #6
0
        static void Main(string[] args)
        {
            Program         p  = new Program();
            DisplayDelegate dd = new DisplayDelegate(Display);

            dd.Invoke(3.42f, 5.6f);
            SumDelegate sd     = new SumDelegate(Sum);
            int         result = sd.Invoke(60, 90);

            Console.WriteLine(result);
            GreetingDelegate gd   = new GreetingDelegate(p.Greeting);
            bool             name = gd.Invoke("kavya");

            Console.WriteLine(name);
            Console.ReadKey();
        }
예제 #7
0
        static void Main(string[] args)
        {
            GreetingDelegate obj = (name) => //Using arrow function then remove keyword delegate, datatype for parameter also removed
            {
                return("Hello " + name + ", Good Morning");
            };
            var str = obj.Invoke("nmfairus");

            Console.WriteLine(str);

            SayHello obj2 = () => { Console.WriteLine("Hello Lambda Expression"); };

            obj2.Invoke();

            Console.WriteLine("Hello World!");
        }
예제 #8
0
        static void Main(string[] args)
        {
            Console.WriteLine("Adding 'GoodMoring' Reference to a Delegate...");
            GreetingDelegate myGreeting = GoodMorning;

            // invoking the delegate
            Console.WriteLine("Invokin Delegate...");
            myGreeting.Invoke("MS");

            // Assiging the addressof the another function to the same delegate
            Console.WriteLine();
            Console.WriteLine("Making Existing Delegate To Point To Another Fuction...");
            Console.WriteLine("Replacing With 'GoodNight' Reference...");
            myGreeting = new GreetingDelegate(GoodNight);

            // Another way of invoking the delegate
            Console.WriteLine("Invoking Delegate...");
            myGreeting("SM");
        }
        static void Main(string[] args)
        {
            DisplayDelegate dd = delegate(float x, float y)
            {
                Console.WriteLine(x + y);
            };

            dd.Invoke(3.02f, 4.2f);
            SumDelegate sd = delegate(int x, int y)
            {
                return(x + y);
            };
            int result = sd.Invoke(60, 90);

            Console.WriteLine(result);
            GreetingDelegate gd = delegate(string name)
            {
                return(true);
            };
            bool name1 = gd.Invoke("friends");

            Console.WriteLine(name1);
            Console.ReadKey();
        }
예제 #10
0
        static void Main(string[] args)
        {
            DisplayDelegate dd = (x, y) =>
            {
                Console.WriteLine(x + y);
            };

            dd.Invoke(3.02f, 6.78f);
            SumDelegate sd = (x, y) =>
            {
                return(x + y);
            };
            int result = sd.Invoke(60, 90);

            Console.WriteLine(result);
            GreetingDelegate gd = name =>
            {
                return(true);
            };
            bool name1 = gd.Invoke("friends");

            Console.WriteLine(name1);
            Console.ReadKey();
        }
예제 #11
0
 /// <summary>
 /// 调用委托
 /// </summary>
 /// <param name="name"></param>
 /// <param name="greetingDelegate"></param>
 public string Greeting(string name, GreetingDelegate greetingDelegate)
 {
     //greetingDelegate.Invoke(name);
     return(greetingDelegate.Invoke(name));
 }
예제 #12
0
        static void Main(string[] args)
        {
            List <int> numbers = new List <int>()
            {
                1, 3, 5, 7, 8, 9, 11, 13, 14, 15
            };

            IEnumerable <int> largeNumber = numbers.Where(c => c > 14);

            foreach (int i in largeNumber)
            {
                Console.WriteLine("Large Number is " + i);
            }

            IEnumerable <int> results = from num in numbers
                                        where num < 3 || num > 7
                                        orderby num descending
                                        select num;

            int count =                 /*(from num in numbers
                                        *  where num < 3 || num > 7
                                        *  orderby num descending
                                        *  select num).Count();*/

                        numbers.Where(n => n < 3 || n > 10).Count();

            Console.WriteLine("Count is " + count);

            foreach (int num in results)
            {
                Console.WriteLine("number is : " + num);
            }

            string[] groupingQuery = { "carrots", "cabbage", "broccoli", "beans", "barley" };
            IEnumerable <IGrouping <char, string> > gQuery =
                from item in  groupingQuery
                group item by item[0];

            foreach (var item in gQuery)
            {
                //Console.WriteLine("Grouped Items are  - ");
            }
            Student.QueryHighScores(1, 90);
            Console.WriteLine("Hello World!");

            MQ app = new MQ();

            int[] nums = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };

            var q1 = app.QueryMethod1(ref nums);

            foreach (string s in q1)
            {
                Console.WriteLine("string is - " + s);
            }

            IEnumerable <string> mq2;

            app.QueryMethod2(ref nums, out mq2);

            foreach (string s in mq2)
            {
                Console.WriteLine(s);
            }

            Student.GroupBySingleProperty();

            FileLogger file = new FileLogger("/Users/giridharreddykatha/Documents/Logs/log.txt");

            Logger.LogMessage(Severity.Error, "This is Error", "This Error is caused");

            Logger.LogMessage(Severity.Critical, "This is Critical Error", "Big  Error");


            AddDelegate ad = new AddDelegate(DelegateDemo.Add);

            ad.Invoke(10, 20);


            MulDelegate md = MulticastDelegate.Area;

            md += MulticastDelegate.Circumference;

            md.Invoke(10.2, 12);

            GreetingDelegate gd = delegate(string name)
            {
                return("Hello " + name + " A Very Good Morning!!");
            };

            Console.WriteLine(gd.Invoke("Friend"));

            GreetingDelegate g = (name) => { return("Hello " + name + " A Very Good Morning!!"); };

            Console.WriteLine(g.Invoke("Mike"));

            Console.ReadLine();
        }
예제 #13
0
 public void GreetPeople(string name)
 {
     delegate1?.Invoke(name);      //通过委托调用方法
 }