A named parameter in C# is a language feature that allows a caller to pass an argument to a method, constructor, delegate, or indexer by explicitly associating the argument value with the parameter’s declared name, bypassing the standard positional matching mechanism. Technically referred to as a named argument at the call site, this feature shifts the binding of arguments to parameters from index-based resolution to name-based resolution during compilation.Documentation Index
Fetch the complete documentation index at: https://docs.syntblaze.com/llms.txt
Use this file to discover all available pages before exploring further.
Syntax and Mechanics
When invoking a method, you prefix the argument expression with the parameter’s exact identifier followed by a colon (:).
Polymorphism and Static Typing
Named arguments are resolved at compile-time against the static type of the reference used for the invocation, not the runtime type of the object. If an interface or base class defines a parameter with one name, but the implementing or derived class uses a different name, the caller must use the parameter name defined by the static type of the variable they are using.Interaction with Optional Parameters
Named arguments are fundamentally integrated with optional parameters. When a method signature defines multiple optional parameters, named arguments allow the caller to provide values for specific optional parameters while omitting others, without needing to supply arguments for every positional parameter in between.Mixing Positional and Named Arguments
C# allows the mixing of standard positional arguments and named arguments within the same invocation, subject to strict compiler rules regarding ordering.- Positional First: Positional arguments can always precede named arguments. Once a named argument is used out of its declared order, all subsequent arguments must also be named.
- C# 7.2+ Positional Trailing: Starting in C# 7.2, a named argument can be followed by a positional argument only if the named argument is placed in its correct ordinal position according to the method signature.
Evaluation Order
When using named arguments out of order, the evaluation of the argument expressions occurs in the order they appear in the calling expression, not the order they are declared in the method signature.Overload Resolution and Modifiers
C# does not allow method overloading based solely on parameter names. A method’s signature for overloading purposes consists strictly of its name and the number, types, and modifiers of its parameters. However, during overload resolution, the compiler evaluates named arguments to filter applicable methods. If a named argument does not match any parameter name in the available valid overloads, the compiler emits error CS1739. Furthermore, named arguments cannot be used to bypassref, out, or in modifiers; the modifier must still precede the argument value at the call site.
Master C# with Deep Grasping Methodology!Learn More





