コード例 #1
0
ファイル: Program.cs プロジェクト: skyras-infotech/swabhav
        static void Main(string[] args)
        {
            // ===== case 1 (Simple Delegate)==========

            // instantiate the delegate (either this way)
            Console.WriteLine("===== case 1 (Simple Delegate)==========");
            DSayAnything obj = new DSayAnything(SayHello);

            // invoke/call the delegate
            obj("Sumit");

            // instantiate the delegate (or this way)
            //DSayAnything obj2 = SayGoodBye;

            // invoke/call using invoke() method
            // obj2.Invoke("Yogesh");

            Action <string, string> obj8 = SayGoodBye;

            obj8("Sehwag", "Virendra");

            // case 6
            Func <string, bool> f1 = SaySomething;

            Console.WriteLine(f1("Mika"));


            // ===== case 2 (Multicast Delegate)==========

            /* Console.WriteLine("===== case 2 (Multicast Delegate)==========");
             * DSayAnything obj3 = SayHello;
             * obj3 += SayGoodBye;
             * obj3.Invoke("Ramesh");*/


            // ===== case 3 (Pass delegate as a parameter)==========

            Console.WriteLine("===== case 3 (Pass delegate as a parameter)==========");
            TakeDelegateAsParameter(SayHello);
            Console.WriteLine();


            // ===== case 4 (Anonymous Method)==========

            Console.WriteLine("===== case 4 (Anonymous Method)==========");
            TakeDelegateAsAnonymouseMethod(delegate(string name)
            {
                Console.WriteLine("Good morning! " + name + "\n");
            });


            // ===== case 5 (Lambda Expression for anonymous method)==========

            Console.WriteLine("===== case 5 (Lambda Expression for anonymous method)==========");
            DSayAnything obj6 = (name) => Console.WriteLine("Good Night! " + name + "\n");

            obj6("Paresh");
        }
コード例 #2
0
        public static void Case3()
        {
            DSayAnything x = (name) => {
                Console.WriteLine("Inside lambda fuction");
                Console.WriteLine("Hello " + name);
            };

            x("Ramesh");
        }
コード例 #3
0
        public static void Case2()
        {
            DSayAnything x = delegate(string name) {
                Console.WriteLine("Inside anonymous fuction");
                Console.WriteLine("Hello " + name);
            };

            x("Suresh");
        }
コード例 #4
0
ファイル: Program.cs プロジェクト: RanchCoder/swabhav
 public static void MessageWizard(DSayAnything fn)
 {
     Console.WriteLine("Inside Message Wizard");
     fn("champ");
 }
コード例 #5
0
ファイル: Program.cs プロジェクト: RanchCoder/swabhav
 public static void MessageForCustomTesting(DSayAnything func)
 {
     Console.WriteLine($"Custom Message");
     func("Vishal is trying to something Different,May god guide him");
 }
コード例 #6
0
        public static void Case1()
        {
            DSayAnything x = InsideNameFunc;

            x("Sumit");
        }
コード例 #7
0
ファイル: Program.cs プロジェクト: skyras-infotech/swabhav
 public static void TakeDelegateAsAnonymouseMethod(DSayAnything obj)
 {
     Console.Write("Call the anonymous method in another method : ");
     obj("Dipak");
 }
コード例 #8
0
ファイル: Program.cs プロジェクト: skyras-infotech/swabhav
 public static void TakeDelegateAsParameter(DSayAnything obj4)
 {
     Console.Write("Call the method in another method : ");
     obj4("Raju");
 }