-
Notifications
You must be signed in to change notification settings - Fork 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
Collection expressions: inferred element type #8582
base: main
Are you sure you want to change the base?
Conversation
|
||
```csharp | ||
foreach (bool? b in [false, true, null]) { } // target type: col<bool?>? | ||
foreach (byte b in [1, 2, 3]) { } // target type: col<byte>? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// target type: col?
would a plain array of target type work? the existing workaround is foreach (byte b in (byte[])[1,2,3]) { }
sharplab shows array is less baggy
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A ReadOnlySpan<T>
is way better (even a Span<T>
is better)
sharplab.io
Working group notes for inferring collection expression element type from best common type of the elements, and potentially choose containing collection type.
Added to meetings/working-group/collection-literals.
Branched from, and replaces, #7864.