You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
The text was updated successfully, but these errors were encountered:
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.
Description
Consider this code:
We get this error for it:
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:
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
intostring[]
to make it compile which is unnecessary.Regression?
No response
Known Workarounds
No response
Configuration
No response
Other information
No response
The text was updated successfully, but these errors were encountered: