Named parameters where order doesn't matter C# 4.0

Hello Friends, It may be possible that you are familiar with C# 4.0 feature called "Named Parameters/Arguments".

If yes then let others know by sharing this post else take a look the power of this feature.

Named arguments free you from the need to remember or to look up the order of parameters in the parameter lists of called methods. The parameter for each argument can be specified by parameter name.
source: microsoft

For an example: A function that prints user details (such as, name, age & profession) can be called in the standard way by sending arguments by position, in the order defined by the function.
myMethods("Mark", 26, "Developer");

If you do not remember the order of the parameters but know their names, you can send the arguments in any order using C# 4.0 feature Named Parameters.

Below is a example and calling of method in each call is valid and will generate same result.

Standard way Named parameters/arguments
Should be in order Order doesn’t matter.
Lack of readability. More readable.
Often developers need to verify assignment of variable values. Not required.

Hi! I am Sartaj Husain. I am a Professional Software Developer, live in Delhi. I write blogs in my free time. I love to learn and share the knowledge with others because it is no good to try to stop knowledge from going forward. So free posts and tutorials. more..

No comments