So you have optional parameters for functions/methods in Visual Basic
.NET, but not in C#?
Mark R. Dawson - 30 Jan 2006 03:30 GMT
correct - optional parameters are not part of the C# language specification,
however the same effect can be achieved by Method overloading for most cases.
> So you have optional parameters for functions/methods in Visual Basic
> ..NET, but not in C#?
Mike Hofer - 30 Jan 2006 21:48 GMT
> correct - optional parameters are not part of the C# language specification,
> however the same effect can be achieved by Method overloading for most cases.
>
> > So you have optional parameters for functions/methods in Visual Basic
> > ..NET, but not in C#?
Mark is right. Optional parameters are a Visual Basic *shortcut* to
method overloading. That's why I tend to avoid them. Plus, in my eyes,
they just look clunky and are harder to maintain.
Clive Dixon - 30 Jan 2006 15:28 GMT
Note that you can create methods with optional parameters in C# using
OptionalAttribute, you just can't consume them from C# (though you can from
VB) and I don't think there's any way of specifying the default value for
the optional argument which is a major limitation anyway - you will just get
the default value for the type I think.
> So you have optional parameters for functions/methods in Visual Basic
> .NET, but not in C#?
Nick Hounsome - 31 Jan 2006 08:29 GMT
> Note that you can create methods with optional parameters in C# using
> OptionalAttribute, you just can't consume them from C# (though you can
> from VB) and I don't think there's any way of specifying the default value
> for the optional argument which is a major limitation anyway - you will
> just get the default value for the type I think.
FYI
There is a well known problem with optional parameters and versioning which
essentially boils down to the same thing as the difference between
public const int x = 3
and
public static readonly int x = 3
One is compile time and one is runtime.
This can cause a lot of confusion if you send out supposedly compatible dll
fix with different optional parameters.
Hans Baumann - 30 Jan 2006 18:17 GMT
you can use variable number of parameters in C#, I guess with the params[]
keyword.... or object[]....
> So you have optional parameters for functions/methods in Visual Basic
> .NET, but not in C#?