Optional parameters are not quite the same as either params[] or
overloading, but overloading usually serves fine.
Where VB's optional parameters come in handy, really, is when you call
into those obscene automation APIs in Office and elsewhere ... you know,
the ones where you have twenty-five parameters and you only need to use
the first two, and furthermore, you likely will never use the other
twenty-three. You can make the same call in C#, but it requires more
effort.
This little convenience is why VB is preferred by some for automation
work, although I suspect it either increases call overhead or involves
late binding under the hood. But it's an edge case. For everyday work,
overloading does the job and arguably does it better.
--Bob
[quoted text, click to view] Joe Cool wrote:
> I take it Optional Parameters for functions are not supported in
In the specific case of an existing API like the one I described, that's
poorly designed in the first place ... no joy. But yes, any time you
have that much info to pass in, it's screaming for a class wrapper.
--Bob
[quoted text, click to view] Alun Harford wrote:
> Bob Grommes wrote:
>> Optional parameters are not quite the same as either params[] or
>> overloading, but overloading usually serves fine.
>>
>> Where VB's optional parameters come in handy, really, is when you call
>> into those obscene automation APIs in Office and elsewhere ... you
>> know, the ones where you have twenty-five parameters and you only need
>> to use the first two, and furthermore, you likely will never use the
>> other twenty-three. You can make the same call in C#, but it requires
>> more effort.
>>
>> This little convenience is why VB is preferred by some for automation
>> work, although I suspect it either increases call overhead or involves
>> late binding under the hood. But it's an edge case. For everyday
>> work, overloading does the job and arguably does it better.
>
> Good advice.
>
> Another option is to go the OO way, and create an object to encapsulate
> the arguments for your method.
>
[quoted text, click to view] Bob Grommes wrote:
> Optional parameters are not quite the same as either params[] or
> overloading, but overloading usually serves fine.
>
> Where VB's optional parameters come in handy, really, is when you call
> into those obscene automation APIs in Office and elsewhere ... you know,
> the ones where you have twenty-five parameters and you only need to use
> the first two, and furthermore, you likely will never use the other
> twenty-three. You can make the same call in C#, but it requires more
> effort.
>
> This little convenience is why VB is preferred by some for automation
> work, although I suspect it either increases call overhead or involves
> late binding under the hood. But it's an edge case. For everyday work,
> overloading does the job and arguably does it better.
Good advice.
Another option is to go the OO way, and create an object to encapsulate
the arguments for your method.
Don't see what you're looking for? Try a search.