.net - Optional VB Parameters are required in C# -
similar this, twist.
vb function declaration:
public shared function myfunc(byval name string, byval num integer, optional byref obj object = nothing, optional byval val integer = 0) boolean
when calling in c# (different solution, copied on .dll
)
error 164 no overload method 'myfunc' takes 2 arguments
metadata shows function be:
public static bool myfunc(string name, int num, ref object obj, int val = 0);
why did 1 optional
make through while other didn't?
c# doesn't support optional ref
parameters. if change obj
byvalue
parameter, should fine.
if try declare optional ref
parameter in c#, you'll violate section 10.6.1 of c# 4 spec:
a fixed-parameter default-argument known optional parameter.
...
a
ref
orout
parameter cannot have default-argument.
the exception com, ref
parameters extremely common. when c# compiler knows it's dealing com component, will allow omit optional ref
parameters.
Comments
Post a Comment