C# 4.0 has brought some new features. One among them are Named and Optional Parameters.
We know something called Overloading in Object Oriented programming, Where we will have same name for methods but will have different parameter. We will call the corresponding method by passing the parameters accordingly.
In C#, we have something called Named parameters. We don't have to pass all the parameters always. We can pass only required parameters.
public void Submit(string name, int Age=20, bool Ismarried=true)
{
// Task to be done...
}
// Note: name must always be provided because it does not have a default value
Optional Parameters:
Calling program:
Submit("God"); //Age and Ismarried became optional
Submit("God",55); // Ismarried bacame optional
Submit("God",55,false); //Passes all the values.
Named Parameters:
Submit("God",Ismarried:true); // We omit age here, which became default.
Submit("God",Age:45); // We omit Ismarried here , which became default.
Submit("God",Age:67;Ismarried:true);
Development work became easy.