C# Tips : Optional and Named Parameters in C#

B

Brian Cryer

Jayesh Sorathia said:
.Net 4.0 Framework provide Optional and Named Parameters in C# also.
Previously it was supported in VB.Net.
Now you do not need to write unnecessary overload methods , With the help
of the Optional method you can achieve this.

The use of optional (and named) parameters, does not make overloaded methods
unnecessary - but it does make some overloaded methods unnecessary which is
what I'm sure you meant. It is just an alternative. In some situations using
overloaded methods will yield code which is clearer and cleaner than you
would get using optional parameters - in others optional parameters will
give you clearer and cleaner code. So use whichever is the most appropriate
in the situation.
 
J

Jayesh Sorathia

The use of optional (and named) parameters, does not make overloaded methods
unnecessary - but it does make some overloaded methods unnecessary which is
what I'm sure you meant. It is just an alternative. In some situations using
overloaded methods will yield code which is clearer and cleaner than you
would get using optional parameters - in others optional parameters will
give you clearer and cleaner code. So use whichever is the most appropriate
in the situation.

Yes Brian , You are right.
I mean in some situations this will remove overloaded methods.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top