c# - Why an identifier is expected while declaring a delegate? -
when create delegate in c#, point function definite signature (parameter set), asks specify identifier each type.
public delegate void mydelegate(int x, int y);
if try write prototype declaration as:
public delegate void mydelegate(int, int)
it shows compile time error saying identifier expected
.
but according me, when specifying prototype method, why compiler needs identifier distinguish between 2 methods different signature:
public delegate void firstdelegate(int);
and
public delegate void seconddelegate(int, int);
are sufficient , clear declaration distinguish between them. think so
i think people got me??
it can make difference @ point of invocation. example:
using system; class test { delegate void foo(int x, int y); static void main() { foo foo = (x, y) => console.writeline("x={0}, y={1}", x, y); foo(x: 5, y: 10); foo(y: 10, x: 5); } }
the output x=5, y=10
both lines, because arguments use names rather positions. though c# gained named arguments in c# 4, vb.net has had them longer.
now of course didn't have that. could have been designed delegates didn't have named parameters in first place - when else invoke has named parameters, why want make delegates different?
would propose same interface methods , abstract methods, way? again, there's no direct use of parameters in declarations, they're signatures.
note parameter names in terms of readability , allow parameters documented more too.
Comments
Post a Comment