What are Named Parameters in C# 4.0 ?

Named Parameters in C# 4.0

What are Named Parameters in C# 4.0 ?

Named Parameters allows developers to not look at the order of parameters in method and developers can pass 1st parameter as 2nd and 2nd parameter as 1st .

Syntax to pass Named parameter is : parameter : value

For example , there is a method SumNumber which calculates sum of paramter a and b

public int SumNumber ( int a , int b )
{
return a+b;
}

Using named paramter , we can this method

SumNumber ( b : 5 , a : 4 );

Named paramters advantages :

  1. Increases code readability
  2. Developer need not remember order of paramters.

One thought on “What are Named Parameters in C# 4.0 ?

Leave a Reply