Re: optional param in Method by Tom
Tom
Tue Mar 18 11:23:24 CDT 2008
On 2008-03-18, Michael D. Ober <obermd> wrote:
> "rowe_newsgroups" <rowe_email@yahoo.com> wrote in message
> news:4f16d1b6-dd78-4127-9083-13ba11263355@q78g2000hsh.googlegroups.com...
>> On Mar 17, 8:30 pm, "Bob Altman" <r...@nospam.nospam> wrote:
>>> > I also would recommend overloading your methods instead of using
>>> > optional parameters. It might just be personal preference, but I
>>> > rarely see any good come out of optional parameters.
>>>
>>> Optional parameters are phenomenally useful for routines authored in and
>>> consumed by VB. But neither C++ or C# are happy with them, so you should
>>> think twice before you use optional arguments on public methods of a
>>> public
>>> class if there is any chance that someone will come along in one of those
>>> languages and try to use your libraries. As I recall, C# is reasonably
>>> benign -- it just treats your optional arguments as required arguments.
>>> C++
>>> issues compiler warnings for any optional arguments it encounters. I
>>> have
>>> no idea what happens if you actually try to call a from C++ that has
>>> optional arguments (I've never tried that).
>>>
>>> Bob
>>
>> Though I'll tend to disagree about there usefulness in VB (I would
>> rather see overloading), your post definitely elaborates on why I
>> always try to leave out the optional params. Outside of upgrading
>> legacy applications without doing to much rewriting, they really
>> should be ripped out and replaced with overloaded methods (imo).
>>
>> Thanks,
>>
>> Seth Rowe [MVP]
>>
>
>
> In addition, methods with optional params are not CLR compliant. No other
> dotNet language can see them.
You can see and call them from C# - it's just really ugly.
> That said, if you are working primarily in VB
> and have internal interfaces that only VB will call, they are extremely
> useful.
Other then maybe reducing typing, they are no more useful then
overloading.
--
Tom Shelton