Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Optional parameters in C#

0 views
Skip to first unread message

Greg Harris

unread,
Jul 13, 2002, 1:25:40 AM7/13/02
to
In VB6 I can declare a method parameter as optional.
Is there some way of doing this in C#?

Thanks


Chad Myers

unread,
Jul 13, 2002, 2:44:40 AM7/13/02
to

"Greg Harris" <gha...@acslink.aone.net.au> wrote in message
news:_TOX8.1889$Cq.9...@ozemail.com.au...

> In VB6 I can declare a method parameter as optional.
> Is there some way of doing this in C#?

Not exactly. There are two things you can do:

- Declare two methods, one with the optional parameter and one
without. Have the one without call the one with and pass in
a default value for the "optional" parameter

- Use parameter arrays. This isn't quite the same thing, but
you should probably know about them.

See 10.5.1.4 in the C# language specification on how to use
param arrays.

ms-help://MS.NETFrameworkSDK/csspec/html/vclrfcsharpspec_10_5_1_4.htm
(watch for URL wrapping)

-c


Benny Tordrup

unread,
Jul 13, 2002, 9:23:46 AM7/13/02
to
I'd absolutely prefer the first!

Benny

"Chad Myers" <cmy...@N0.SP.4M.austin.rr.com> wrote in message
news:s%PX8.106278$q53.2...@twister.austin.rr.com...

0 new messages