1234567891011121314151617181920212223242526272829303132333435363738394041424344 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Runtime.Remoting.Messaging;
- using System.Text;
- using System.Threading.Tasks;
- namespace ConsoleDelegateAnonymous
- {
- class Test
- {
- public int Add(int x, int y)
- {
- return x + y;
- }
- }
- internal class Program
- {
-
- public delegate int DAdd(int x, int y);
- static void Main(string[] args)
- {
- Test test = new Test();
-
- DAdd d = test.Add;
-
- int num = d(2, 3);
- Console.WriteLine("num:" + num);
-
- DAdd d1 = delegate(int x,int y)
- {
-
-
- return x + y;
- };
-
- int num2 = d1.Invoke(5, 6);
- Console.WriteLine("num2:" + num2);
- Console.ReadLine();
- }
- }
- }
|