3 ms·
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 "
by zmj 3y ago
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-reference/proposals/csharp-12.0/collection-expressions https://learn.microsoft.com/en-us/dotnet/csharp/language-ref...
- nesarkvechnep 3y agoYep, just like withHM type inference, it infers the most concrete type from the usage.
- mpawelski 3y agoYou 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#issuecomment-1662891250 https://github.com/dotnet/csharplang/issues/5354#issuecommen...)