Skip to content

Query comprehension extensions to collection initializers #216

@AnthonyDGreen

Description

@AnthonyDGreen

Today in VB you can write a query expression: From v In c Where P(v) and you can write New List(Of T) From { ... }. Is it a natural extension that New List(Of T) From v In c Where P(v)?

I think so, but that's purely an accident of the syntax we've chosen for collection initializers--that it happens to use the From keyword. Curious what others think?

It would provide an easier syntax for "list comprehensions" that other language have.

Note: This begs that we extend type inference for New expressions to do some type argument inference based on collection initializer values: New List From x In 1 To 100 Step 2 Select x * x ' List of squares. It's not as concise as just using [ ] like other languages, but what have cryptic symbols ever done for me?

Is this syntactic sugar for New List(Of T)(initializer)? That's probably easier than looping and calling Add a whole bunch of times (and quite possibly more performant) but wouldn't be the same for nested collection initializers to read-only properties.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions