DQbJA%{gp?ciP'yyyyyyyyyyDQ!JAiy%ggby,`wiyg3y,`wiyg3'0#O'0#O5u?cgg?cgg?cgiPmq+aAabDEBCAeeeCXC| 64VBCWC }4AWCWW

Named parameters` are an alternate parameter syntax. They sometimes result in easier to read and clearer code. They are checked for correctness by the compiler. By specifying the formal parameter name, we can reorder arguments.`Example.` In Main, we use the syntax "name:" and then a string literal to specify the value of the name parameter. The syntax "size:" and then an integer signifies the size parameter. You can reorder these named parameters in any way you want. `You can specify names on only some parameters, using the positional syntax for some arguments.`In the C# language,` programs are compiled into a high-level abstract assembly language. For the named parameters feature, the compiler uses temporary local variables. It then reorders those locals in the argument slots. `Intermediate Language `il`For named parameters, the compiler simply infers the regular order from the new syntax.`Performance.` The intermediate language representation of named parameters introduces extra local variables and assignments before passing the arguments. To demonstrate the performance effect, we introduce two methods, Method1 and Method2. `In these methods, a third method Method3 is called with named parameter syntax and classic parameter syntax.`Please disregard the logic of Method3 as it is there mainly to ensure the method is not inlined.`The results` for the .NET Framework 4.0 are interesting. They show that named parameters have a substantial performance drawback. The likely reason for this is that the named parameters are transformed into local variables. `So: `As Method1 is called, memory on the virtualized stack must be allocated each time.`Therefore: `More stack memory is used. This causes performance to suffer, making each method call slower.`It is unfortunate` that the C# compiler cannot optimize named parameter calls into the performance equivalent of regular method calls. If every method call on your computer was 2.5 nanoseconds slower, your computer would be miserable. `Thus: `Named parameters should be avoided in most C# program contexts where they do not dramatically increase readability.`Summary.` The named parameters feature in new versions of the C# language introduces syntactic sugar for method calls. Perhaps most intriguing, this feature embeds more contextual information into method calls. `This makes source text possibly clearer to read and understand. This can lead to less buggy programs.

FHI HHHHH { FHF{I FFHCall the Test mH several timesHdifferent ways. FFITest(name: "Perl", size: 5); FFTest(name: "Dot", size: -1); FFTest(6, "Net"); FFTest(7, name: "Google"); F} FHHTest(Hsize, H name) F{ FFHI"SizeH{0}, NameH{1}"I, size, name); F} } I SizeH5, NameHPerl SizeH-1, NameHDot SizeH6, NameHNet SizeH7, NameHGoogleI HH; H HH { Fconst H_maxH100000000; FHF{ FFMH1(); FFMH2()HFFvar s1HH.HNew(); FFH(HiH0; i < _max; i++) FF{ FFFMH1(); FF} FFs1H; FFvar s2HH.HNew(); FFH(HiH0; i < _max; i++) FF{ FFFMH2(); FF} FFs2H; FFH(H(s1.H * 1000 * 1000) / FFF_max).ToH("0.00 ns")); FFH(H(s2.H * 1000 * 1000) / FFF_max).ToH("0.00 ns")); FFH.H(); F} FHHMH1() F{ FFMH3(flag: true, size: 1, name: "Perl"); F} FHHMH2() F{ FFMH3(1, "Perl", true); F} FHHMH3(Hsize, H name, bool flag) F{ FFH!flag && size != -1 && name != null) FF{ FFFthrow HH(); FF} F} } I I2.88 nsI [named parameters] I0.33 nsI

"`Anamed parameterstests named parameter performance