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

error CS9176: There is no target type for the collection expression #102130

Closed
Nefcanto opened this issue May 12, 2024 · 1 comment
Closed

error CS9176: There is no target type for the collection expression #102130

Nefcanto opened this issue May 12, 2024 · 1 comment
Labels
needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners

Comments

@Nefcanto
Copy link

Description

Consider this code:

var names = [
    "John",
    "David"
];

We get this error for it:

error CS9176: There is no target type for the collection expression

The target type is clear. It's an array of strings.

Reproduction Steps

1- Create a simple console app
2- Add this code to it:

var names = [
    "John",
    "David"
];

3- Compile

Expected behavior

No error should be thrown. The program should compile. The variable is an array of strings. This is the universal behavior in almost any language, including JavaScript and Python.

Actual behavior

It does not compile. We need to change the var into string[] to make it compile which is unnecessary.

Regression?

No response

Known Workarounds

No response

Configuration

No response

Other information

No response

@dotnet-issue-labeler dotnet-issue-labeler bot added the needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners label May 12, 2024
@dotnet-policy-service dotnet-policy-service bot added the untriaged New issue has not been triaged by the area owner label May 12, 2024
@huoyaoyuan
Copy link
Member

This is a C# language question and should go to https://github.com/dotnet/csharplang/discussions. The natural type of collection expression is still being designed at https://github.com/dotnet/csharplang/blob/main/proposals/collection-expressions-next.md#natural-type and dotnet/csharplang#7913.

This is the universal behavior in almost any language, including JavaScript and Python.

It is not. JavaScript and Python do not have different collection types that provide different performance characteristics. There's only one weakly typed "array list".
Collection expression is more like std::initializer_list in C++, that can be accepted by different collection types.

Closing as not a runtime issue.

@huoyaoyuan huoyaoyuan closed this as not planned Won't fix, can't repro, duplicate, stale May 12, 2024
@dotnet-policy-service dotnet-policy-service bot removed the untriaged New issue has not been triaged by the area owner label May 12, 2024
@github-actions github-actions bot locked and limited conversation to collaborators Jun 12, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners
Projects
None yet
Development

No branches or pull requests

2 participants