how do stacks, lists, arrays, etc have a collection expression?
is it part of the compiler or is there a special function or attribute you can give code in order for it to work that way?
1 Reply
https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/operators/collection-expressions
It's a compiler thing
Basically "figure out how to initialize it in the most optimal way for me"
For your own collection types to support it, as the docs say, you need the
[CollectionBuilder]
attribute and a builder class with Create()
method