-
Notifications
You must be signed in to change notification settings - Fork 4.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Suggestion: Allow ignored lambda parameters to have the name _ #2397
Comments
Doesn't work for vb.net |
Well it does not necessarly need to be the underscore. I could also imagine somethind like: |
Since the pattern matching spec is very likely to include a wildcard, which thus far as been Note that |
@xbelt I also like the look of the second option |
My suggestion is for C# although it might be useful for vb too but I don't use that language, Using the underscore for this would not be a breaking change in C# as long as the rule is specified to be that "if more than one symbol in a scope has the name _, an error is not issued but none of those symbols can be accessed". It is not a breaking change because such program is illegal today. |
Maybe, but it would be silly to have multiple wildcard operators in different contexts. If pattern matching is going to use |
@HaloFour Yes, the syntax should definitely align with that of pattern matching. |
This is probably done now with |
Not just yet. AFAIK it only works on patterns, out var, deconstructors and simple assignments. |
I'll go ahead and close this language proposal in favor of the one in the csharplang repo dotnet/csharplang#111 |
When writing lambdas you quite often end up not caring about all parameters, but you need names for them anyway. In F# you can use
_
as the name for such parameters, and that is also possible in C# but only as long as there is only one such parameters. If there is more than one you need to come up with names (or use names such as_1
,_2
etc).My suggestion is to allow multiple symbols in the same scope be named
_
. Of couse, when doing this you can't use any of the symbols with that name, but it will enable you to write things likeMyMethod((a, _, _) => a + 1)
which is sometimes convenient (especially when using mocking libraries).The text was updated successfully, but these errors were encountered: