Archive for June, 2009

In my last post I had discussed about optional arguments and default values.In continuation to that today we will take a look into the named arguments feature.Let us consider the method definition and invocation as shown below:


class Program {
       static void Main(string[] args) {
           Foo f = new Foo();
           f.PrintName("Sankarsan", "S", "Bose");
           Console.ReadLine();
       }
   }
   public class Foo {
       public void PrintName(string firstName, string lastName, string middleName ) {
           Console.WriteLine("Name is {0} {1} {2}", firstName, middleName, lastName);
       }

}

Here the PrintName method is invoked using what is called positional arguments where the value of the parameters are determined by their position in the parameter list.In C# 4.0 we can do it like this using named arguments:

(more…)

Advertisements