Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Collection expressions are somewhere between spooky and very cool. If you don't specify a concrete type for the collection, the compiler is free to choose the "best" option given your usage of the collection:

https://learn.microsoft.com/en-us/dotnet/csharp/language-ref...



You must specify concrete type.

There was a plan to have "natural type" so "var list = [1,2,3]" would be of type "List<int>" but it was postponed to C# 13 (https://github.com/dotnet/csharplang/issues/5354#issuecommen...)


Yep, just like withHM type inference, it infers the most concrete type from the usage.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: