In the .NET Framework, there are interfaces for immutable dictionaries, lists, queues, sets, stacks.
But there is no interface for immutable arrays to be found.
Also, immutable arrays are implemented as a struct in contrast to others which are class.
Can you explain why such design?
In general interfaces and classes don't have an one-to-one relationship in .NET. For example see a recent comment by a Microsoft engineer on GitHib:
By "collection abstractions" they mean interfaces. Some immutable collections do have such a relationship, like the
ImmutableQueue<T>collection and theIImmutableQueue<T>interface, but you could see them more as an exception than the rule.The
ImmutableArray<T>struct is interesting. You can learn why it was implemented as astructin this blog post by Immo Landwerth. Quote:The
ImmutableArray<T>implements many interfaces, but if you store it as an interface in a variable or field, it will be boxed. So you generally don't want to do this. Preferably you'd want to store it and pass it around as is.