Skip to content
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

Open
wants to merge 29 commits into
base: main
Choose a base branch
from

Conversation

cston
Copy link
Member

@cston cston commented Nov 12, 2024

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.

@cston cston requested a review from a team as a code owner November 12, 2024 20:02
@cston cston requested a review from CyrusNajmabadi November 12, 2024 20:03
@cston cston requested review from jnm2 and RikkiGibson November 12, 2024 20:03
@cston cston requested review from jnm2 and removed request for jnm2 November 15, 2024 17:21

```csharp
foreach (bool? b in [false, true, null]) { } // target type: col<bool?>?
foreach (byte b in [1, 2, 3]) { } // target type: col<byte>?

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

Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants