Skip to content

Non-trailing named arguments C# 7.2code reduction

Use named arguments in any position when positional arguments follow.

In prior versions of C# once a named argument was used all subsequent arguments had to be named.

This can be quite restrictive in some scenarios, such as when wanting to specify the name for boolean arguments for clarification but not wanting to name all subsequent more obvious arguments.

Code ​

csharp
UpdateOrderStatus(orderId, shipped: true, trackingId);
csharp
UpdateOrderStatus(orderId, shipped: true, tracking: trackingId);

Notes ​

  • A named argument can only be followed by positional arguments when it is in its correct position in the method signature.

More information ​

Powered by Intracia