Thursday, November 19, 2009

Named parameters in C# (.NET Framework 4.0 only)

It is a welcoming change in C# in Framework 4.0, to accept named parameters and optional arguments which was available in Visual Basic versions for a long time.

Here is how we can use named arguments in C#.

//Consider the following function.
public int Sum(int a, int b)
     return a + b;

//To use named arguments for the above function we use as under.
int result;
result = Sum(a: 10, b: 20);

No comments:

Post a Comment