Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / New Users / January 2006

Tip: Looking for answers? Try searching our database.

Optional Parameters

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Water Cooler v2 - 30 Jan 2006 00:32 GMT
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#?

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.