Geeks With Blogs
Developers Friendly

.NET provides an useful feature call as named & optional parameter. With the help of this we can avoid getting in to situation, where accidentally changing the position of parameter and getting in to logical error. And in order to call specific function by changing value couple of parameters and retaining values of other parameter we will pass all parameters with default value or null or “”.

Named Parameter:

In named parameter, we will pass value to parameter be referring name of the parameter instead of following the order. The benefit of using named parameter is that, we can change the order in which we pass parameter.

Below example should be easier to understand,

NamedParameter

 

Output of the above program would look like,

OutputNamedParameter

 

Optional Parameter:

In optional parameter, we will set some default value to parameter. In such cases, if we don’t send any value to parameter, that default value will be considered. If we pass any value to parameter then the value which we passed will be considered.

Below example should be easier to understand,

OptionalParameter

 

Output of the above program will looks like,

OutputOptionalParameter

 

 

Thanks!

Posted on Monday, July 29, 2013 2:32 PM .NET | Back to top


Comments on this post: Named and Optional Parameter

No comments posted yet.
Your comment:
 (will show your gravatar)


Copyright © Manjunath K | Powered by: GeeksWithBlogs.net