Thursday, February 26, 2009

C# 4.0 Optional and Named Arguments.


Visual basic supports Optional  Parameters.  But Visual C# 2.0  or 3.0 we basically define Function overloading to achieve this. but in C# 4.0 we can define a method with Optional parameters . 

when declaring a parameter is optional we just simply provide default value  for it.  please look at the code sample I have defined two methods with optional parameter providing default value.



Named Arguments

Named arguments is a way to provide an argument using the name of the corresponding parameter instead of relying on its position in the parameter list.

for example the  method GetFullName  defined as


But when i  am invoking i am passing lname as first parameter and fname as second parameter  where as in function it defined as reverse.



Sreenivasa ragavan.

No comments: