In -depth understanding of the method group in C#
In C#, you may encounter an error that prompts that the "method group" does not match the values of other types (such as string). This error occurred when trying to assign a method group to variables, but did not use parentheses to call this method.
What is the method group?
The method group is a set of methods to share the same name. In the provided example, represents a method group, which contains all the methods defined by . This includes the default method and any expansion method of the name of the
name.
someObject.ToString
Why is it important to re -loading? someObject
ToString
When the method group is not used with brackets, the overload analysis mechanism of C#will not be applied. Therefore, the compiler cannot determine which method to call. Add brackets for compulsory loading analysis, which will clearly identify specific methods to be executed according to the parameter types provided. ToString()
ToString
The correct way of use
In the example provided, the correct method of use is as follows:
The above is the detailed content of What's the Difference Between a Method Group and a Method Invocation in C#?. For more information, please follow other related articles on the PHP Chinese website!