Tuesday, January 24, 2012

How to use Optional Parameter in C#


We can use optional parameter by the following  way:
Solution:
Syntax :
=====
We need to set "string Id=""" called as optional parameter
Here "string Id=" is the variable declaration
all the optional parameters should declare after required parameters

 example:
=============
private void GetSelectedItems(Label lbltest,string Id="")
{
    
}

//calling function using optional parameter
          GetSelectedItems(mylable,"lbltest");

//calling function without using optional parameter
 GetSelectedItems(mylable);

No comments:

Post a Comment