jae-l
6/12/2017 - 12:51 AM

Example of how to use optional arguments with methods.

Example of how to use optional arguments with methods.

static void PrintStuff(int i, int j = 4, string s = "optional string")
{
  Console.WriteLine(i + " " + j + " " + s);				
}

static void Main(string[] args)
{
  PrintStuff(100);
  PrintStuff(4, j: 25, s: "chosen string");
  PrintStuff(j: 89, i: 27);
  PrintStuff(50, s: "another chosen string");
}

//  100 4 optional string
//  4 25 chosen string
//  27 89 optional string
//  50 4 another chosen string