コード例 #1
0
        static void Main(string[] args)
        {
            //Console.WriteLine("Hello World!");
            //var result = User<string>.Test("ab", "ab");
            //Console.WriteLine(result);
            testdelegate objtestdelegate = new testdelegate(User.Printmsg);

            //   User.Printmsg("Hello");    //Without Delegates
            objtestdelegate("Dilip Sarvaiya");  //Using Delegates
            List <User> userList = new List <User>();

            userList.Add(new User()
            {
                ID = 1, name = "First", Experience = 5
            });
            userList.Add(new User()
            {
                ID = 2, name = "Second", Experience = 6
            });
            userList.Add(new User()
            {
                ID = 3, name = "Third", Experience = 8
            });
            userList.Add(new User()
            {
                ID = 4, name = "Forth", Experience = 5
            });

            IsUser objUser = new IsUser(userMethod);

            User.PrintUser(userList, objUser);
        }
コード例 #2
0
        static void Main(string[] args)
        {
            int a  = 0;
            int b  = 1;
            var td = new testdelegate(fibo);

            td(a, b);
            Console.Read();
        }
コード例 #3
0
        static void Main(string[] args)
        {
            testdelegate idelegate = new testdelegate(consolestr); //method1 实例化委托

            idelegate("1 instance delegate");                      //方法一 调用委托



            testdelegate adelegate = delegate(string s) { Console.WriteLine(s); };  //method2 匿名委托



            adelegate("2 anonymous delegate");


            //method 3 lambda expression
            testdelegate ldelegate = (s) => { Console.WriteLine(s); };

            ldelegate("3 lambda delegate");
        }