The example in this article describes how C # uses anonymous methods to define the implementation of a delegate. Share to everyone for your reference. The implementation methods are as follows:
?
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
Define delegate class program with anonymous method {delegate string Mydelagate (string val); static void Main (string[] args) {string str1 = "anonymous method external "; The brackets section defines a method with no name, and the compiler will specify a name mydelagate my = delegate (string param) {string str2 = "Inside anonymous method"; return param + str1 + str2; }; Calls the delegate's anonymous method Console.WriteLine (My ("parameters")); As can be seen from the result, the anonymous method also achieves the effect of defining the method for the delegate console.read (); } } |
I hope this article will help you with the C # program.