Code Snippet posted by:
Satyadevanand | Posted on: 10/18/2012 | Category:
C# Codes | Views: 200 | Status:
[Member] |
Points: 40
|
Alert Moderator
c# 4.0 introduced a new concept optional parameters
Usage of
Optional Parameters
Method
class Class1
{
static void OptParams(int i = 10, int j = 20)
{
Console.WriteLine("i=" + i);
Console.WriteLine("j=" + j);
}
static void Main(string[] args)
{
OptParams();//10,20
OptParams(40);//40,20
OptParams(70, 90);//70,90
}
}
OptParams();
Output:
i=10
j=20
------------------------------
OptParams(40);
Output:
i=40
j=20
----------------------------------
OptParams(70,90);
Output:
i=70
j=90