예제 #1
0
        static void Main(string[] args)
        {
            DisplayInfo normalDelegate = new DisplayInfo(GetInformation);

            DisplayInfoBasedOnNumber oneParameterDelegate = new DisplayInfoBasedOnNumber(GetInformation);

            oneParameterDelegate(100);

            DisplayInfo normalDelegateAnonymous = delegate { Console.WriteLine("Hi from the anonymous method"); };

            normalDelegateAnonymous();

            DisplayInfoBasedOnNumber oneParameterDelegateAnonymous = delegate(int number)
            { Console.WriteLine("Hi from the anonymous method which takes one int parameter" + number); };

            oneParameterDelegate(150);
        }
예제 #2
0
        static void Main(string[] args)
        {
            DisplayInfo normalDelegate = new DisplayInfo(GetInformation);

            normalDelegate();
            //without new delegate ctor
            DisplayInfoBasedOnNumber oneParameterDelegate = GetInformation;

            oneParameterDelegate(200);

            Console.WriteLine("---------------------");

            DisplayInfo normalDelegateAnonymous = delegate { Console.WriteLine("hi from anonymous method"); };

            normalDelegateAnonymous();

            DisplayInfoBasedOnNumber oneParameterDelegateAnonymous = delegate(int number) { Console.WriteLine($"hi from anonymous int i = {number}"); };

            oneParameterDelegateAnonymous(100_000);
        }
예제 #3
0
        static void Main(string[] args)
        {
            DisplayInfo normalDelegate = new DisplayInfo(GetInformation);

            normalDelegate();

            DisplayInfoBasedOnNumber oneParam = new DisplayInfoBasedOnNumber(GetInformation);

            oneParam(4);


            Console.WriteLine("--------------------------");
            DisplayInfo normalDelegateAnon = delegate { Console.WriteLine("Hi from a anon method!"); };

            normalDelegateAnon();

            DisplayInfoBasedOnNumber anonParamDel = delegate(int number) { Console.WriteLine("Hi from the anon method wich takes a param: " + number); };

            anonParamDel(5656);

            Console.ReadKey();
        }