This article describes the implementation method of C# using anonymous method to define delegates. Share it for your reference. The specific implementation method is as follows:
//Define the delegate using anonymous methodclass Program { delegate string MyDelagate(string val); static void Main(string[] args) { string str1 = "Anonymous Method External"; //The brackets define a method. If there is no name, the compiler will specify a name. MyDelagate my = delegate(string param) { string str2 = "Inside the Anonymous Method"; return param + str1 + str2; }; //Calling the anonymous method of the delegate (my(" Parameters ")); // From the results, we can see that the anonymous method also achieves the effect of defining the method for delegate (); } }
I hope this article will be helpful to everyone's C# programming.