Version Used: 16.6.4, SharpLab shows it on master
There's a lot of code out there like this:
using System.Linq;
class C
{
void M()
{
// ❌ CS0103 The name '_' does not exist in the current context
// ↓
Enumerable.Range(0, 1).Select(_ = _.ToString());
}
}
This doesn't follow the spec in https://github.com/dotnet/csharplang/blob/master/proposals/lambda-discard-parameters.md#detailed-design:
Note: if a single parameter is named
_then it is a regular parameter for backwards compatibility reasons.
CC: @jcouv This should be covered by the test plan #38820
- [x] that a single
_is not a discard parameter (ie. is in scope and can be read from) (seeDiscardParameters_NotADiscardWhenSingleUnderscore)
I'm confused. There is no lambda in the example. Did you mean .Select(_ => _.ToString()) with a =>?
Oh my, I'm so sorry! Wow 😆
Most helpful comment
Oh my, I'm so sorry! Wow 😆