By design why is it mandatory to specify parameter names when declaring delegate type?
Why must we specify the parameter name x
as follows
public delegate void XXX(int x);
when declaring a delegate type?
For me, the parameter name x
is unused so it will be simpler if we can rewrite as follows:
public delegate void XXX(int);
Please let me know why the C# designer "forced" us to specify the parameter names.
Edit1:
Is public delegate TResult Func<T1,TResult>(T1 arg1)
more readable than public delegate 开发者_开发技巧TResult Func<T1,TResult>(T1)
?
It is used:
- when coding an invoke, to provide sensible intellisense and to help the developer know which of 4 strings to pass in which position to a method(string,string,string,string) (for example)
- in other tooling - for example implementing an event (or other delegate) and pressing tab to have the tooling generate a method stub (the parameter names from the delegate become the parameter names of the method-stub)
In both cases this name adds meaning that aids the developer. For example, I have no idea what your x
represents - but name it something better and I'll have a clue.
As an alternative, use Action<int>
and forget about it.
Probably the same reason as you are forced to specify the name of a method parameter. For one thing it helps to document the purpose of the parameter.
Which is more readable?
public delegate void EventHandler(object source, EventArgs e);
public delegate void EventHandler(object, EventArgs);
精彩评论