With the release of .NET 4.0 C# programmers are now able to created methods with optional parameters like VB programmers doing. Optional arguments are widely used in VBA for long time. Although they make life a little bit easier for programmers (you don’t have to repeat default values in your method calls).

Code Snippet
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5.  
  6. namespace optionalParameters
  7. {
  8.     class Program
  9.     {
  10.         static void Main(string[] args)
  11.         {
  12.             OptionalParameterTest t = new OptionalParameterTest();
  13.             Console.WriteLine("Optional Parameter :  {0}", t.OptionalParameter("One"));
  14.             Console.WriteLine("Optional Parameter :  {0} ", t.OptionalParameter("One1", "Two1"));
  15.             Console.WriteLine("Optional Parameter :  {0} ", t.OptionalParameter("One1", "Two1","three1"));
  16.             Console.WriteLine("Optional Parameter :  {0} ", t.OptionalParameter("One1", "Two1","Three1","Four1"));
  17.             Console.ReadLine();
  18.  
  19.         }
  20.  
  21.     }
  22.     public class OptionalParameterTest
  23.     {
  24.         public string OptionalParameter(string  one, string two = "Two",string three="Three",string four="Four")
  25.         {
  26.  
  27.            
  28.             return one + "  " + two + "  " + three + "  " + four;
  29.         }
  30.     }
  31.  
  32. }

Optional Parameters