I beleive most of you know about overloading in oops.Well,to have some optional parameters some time before, we had to rely on overloading itself.But now things have changed & with the introduction of Optional Parameters in C#4.0,it’s going to be really easy. This is how it will look like.
public void ExampleMethod(int required, string optionalstr = "default string",int optionalint = 10)
The following call to ExampleMethod causes a compiler error, because an argument is provided for the third parameter but not for the second.
However, if you know the name of the third parameter, you can use a named argument to accomplish the task.
ExampleMethod(3, optionalint: 4);
public void ExampleMethod(int required,int optionalint = 10,string optionalstr = "default string")