Optional parameters

Satyadevanand
Posted by Satyadevanand under C# category on | Points: 40 | Views : 867
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

Comments or Responses

Login to post response