Proposal for Enhancing the Delegate Syntax in C# #8343
Replies: 5 comments 20 replies
-
I personally would also like to see unification between function pointers ( Sadly, the work involved to do this with C# now is probably not worth it. |
Beta Was this translation helpful? Give feedback.
-
I think rather than new syntax on top of existing delegates, this would play nicely with new struct delegates. #7785 (this is also what I was imagining in my alternative section). I'm not sure if this is do-able in only C# compiler, and would probably need to rely on the runtime implementing the delegate types, so that delegate from assembly A matches delegate with the same signature from assembly B. |
Beta Was this translation helpful? Give feedback.
-
If we're going to change the delegate syntax, then I think following the way it's done in Typescript is a much better proposal. I know I've seen such a proposal before, but I couldn't find it looking it up now, but the gist of it is this:
|
Beta Was this translation helpful? Give feedback.
-
private int delegate<int, string> MyMethodDelegate ... Your proposal does not specify how this signature would be emitted into IL. Under the hood delegates are nominal types, not structural. That means a concrete type must be emitted for |
Beta Was this translation helpful? Give feedback.
-
Proposal Summary:
Transform the delegate keyword to prefix variable declarations, indicating that the variable is a reference to a function or method. This would allow for a more natural and comprehensible syntax while preserving all existing benefits of delegates and Func constructs.
Example Syntax:
C#
Benefits:
This enhancement would streamline the use of high-order functions in C#, making the language more powerful and user-friendly.
Thank you for considering this proposal. I believe it could significantly improve the developer experience with delegates in C#.
May you walk with God always,
Sam
Beta Was this translation helpful? Give feedback.
All reactions