#593 – Using Named Arguments
May 29, 2012 4 Comments
Traditionally in C#, arguments must be passed in to a method in the same order in which they are defined in the method’s declaration.
public void DoATrick(string trickName, int numTimes)
Dog kirby = new Dog("Kirby"); kirby.DoATrick("Fetch", 158);
You can, however, change the order of the arguments by preceding each value by the name of the parameter, with a colon (:) following each name.
kirby.DoATrick(numTimes: 5, trickName: "Run around me");
Pingback: #594 – When You’d Want to Use Named Arguments « 2,000 Things You Should Know About C#
Pingback: #693 – Named Arguments in Constructors Allow the Most Flexibility « 2,000 Things You Should Know About C#
Pingback: #815 – Named vs. Positional Arguments | 2,000 Things You Should Know About C#
Pingback: #816 – Named Argument and Optional Parameter Combinations | 2,000 Things You Should Know About C#