Peter Duniho wrote:
> On 3/24/11 1:48 PM, Rick Lones wrote:
>> When I declare a delegate signature thusly . . .
>>
>> private delegate void eventHandler(EventWaitHandle ewh);
>>
>> . . . can someone explain why the "ewh" identifier is required? It
>> appears completely superfluous to me - the parameter type(s) and
>> position(s) seem like all that should be needed. This is .Net 2.0 BTW,
>> dunno what changes in later incarnations.
>
> It's the same in all versions of the language. And yes, the parameter
> name is theoretically superfluous. However, note that delegate types
> use the same data structure to define the signature as for methods, the
> MethodInfo type (which you can retrieve from the delegate type by
> getting the MethodInfo for the Invoke() method on the type), and the
> MethodInfo type has to include parameter names.
>
> I suppose the compiler could have just put in some placeholders, but it
> seems to me that for those moments when one is in fact looking at the
> parameter names (either in the type declaration or via reflection),
> having meaningful parameter names is very useful. The type alone is
> often insufficient to explain how a parameter should be used (e.g.
> "sender" in the EventHandler delegate type).
It's been so long I had to peek at an old C header file to be sure that the
parameter was not required in, e.g., an extern declaration. It seems basically
an artifact then but one of "intelligent design". I do see some advantages,
especially as regards your point re MethodInfo. Thanks.
-rick-
|