Proposal: Generic Named Type Arguments #8272
-
Proposal: Generic Named Type ArgumentsSummaryIntroduce named type arguments in C# to specify type arguments by name at invocation time. This feature aims to simplify generic method invocations, improving code readability and maintainability. MotivationCurrently, when invoking generic methods with multiple type parameters, developers often need to specify all type arguments explicitly. This can lead to verbose and less readable code, especially when type inference is not straightforward. Named type arguments at invocation time would simplify this process by allowing developers to specify only the necessary type arguments by name. ProposalIntroduce syntax for named type arguments in C# at invocation time. For example: Current state//For this signature
TIn Process<TIn, TOut>(TIn input);
// Current invocation syntax
string result = Process<int, string>(45); Possible workaroundA possible workaround would be defining this signature TIn Process<TIn, TOut>(TIn input, TOut output); And call string result = Process(45, default(string)); 🎉 Proposed syntax with named type arguments will infer
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Duplicate of #1349. |
Beta Was this translation helpful? Give feedback.
Duplicate of #1349.