Thursday, April 26, 2012

Use Optional Parameters c#

What is the need for that ??

You need to define a method with some optional parameters......

So what will you do for that ???

Simple : Supply some default parameter in the method arguments. :)

Here is the example for that :




void PrintMyMessageDude()
{
    PrintMyMessageDude("Adam");
}
 
void PrintMyMessageDude(string from)
{
    PrintMyMessageDude(from, "Hello");
}
 
void PrintMyMessageDude(string from, string message)
{
    PrintMyMessageDude(from, message, false);
}
 
void PrintMyMessageDude(string from, string message, bool urgent)
{
    
}

This will help and allow caller of the method to be based on the default paramenters and the supplied parameter.

So this can be seen as polymorphism too  right :)




No comments:

Post a Comment

Thank you for Commenting Will reply soon ......

Featured Posts

#Linux Commands Unveiled: #date, #uname, #hostname, #hostid, #arch, #nproc

 #Linux Commands Unveiled: #date, #uname, #hostname, #hostid, #arch, #nproc Linux is an open-source operating system that is loved by millio...