Hello everyone,
After quite some time study on samples and C# Spec. I am confused about what is a method group? In my understanding method group is a set of methods which have the same signature, and not necessary to belong to a specific class. But I am not sure whether I am correct. Any comments or ideas?
Below is what I found in my study.
From ECMA-334: 14.1,
http://en.csharp-online.net/ECMA-334:_14.1_Expression_classifications
A method group, which is a set of overloaded methods resulting from a member lookup (§14.3). A method group can have an associated instance expression. When an instance method is invoked, the result of evaluating the instance expression becomes the instance represented by this (§14.5.7). A method group can be used in an invocation-expression (§14.5.5), used in a delegate-creation-expression (§14.5.10.3), or implicitly converted to a compatible delegate type. In any other context, an expression classified as a method group causes a compile-time error.
From C# in Depth,
http://csharpindepth.com/ViewNote.aspx?NoteID=92
"the feature allows you to specify an extension method as a method group using extension syntax"
thanks in advance,
George
George GeorgePosted Sep 11, 2008, 9:13 PM
Thanks Jon,
Your answer is quite clear. :-)
Let me confirm, you mean method groupd are a group of methods which are all the candidates when we make a method call. But actually which method in the candidate methods will be called is dependent on the method look-up priority and sequence. Is that correct understanding?
My current confusion is I am not sure whether it should be all the methods with the same name be called method group -- or only the candidate methods which ar eligible to be called according to C# syntax and runtime parameter type checking/conversion are called method group.
regards,
George
Jon SkeetPosted Sep 10, 2008, 9:04 AM