[Proposal]: Inline arrays (VS 17.7, .NET 8)
Inline arrays
- [x] Proposed
- [x] Prototype: Done
- [x] Implementation: Done
- [ ] Specification: Not Started
Summary
This feature recognizes the special meaning of the [InlineArray] attribute, allows indexing into such inline array types and enumerating their elements.
See https://github.com/dotnet/csharplang/blob/main/proposals/csharp-12.0/inline-arrays.md
Design meetings
https://github.com/dotnet/csharplang/blob/main/meetings/2024/LDM-2024-06-17.md#inline-arrays-as-record-structs
Is there a proposal to allow initializing an InlineArray using a collection expression? Right now the only way (I think) is to use CopyTo from a span, I couldn't find any discussion on that.
There is not currently. It was dropped due to lack of time. A proposal could be raised! It would have to deal with what to do with spreads into a fixed-length collection. Silently under-initialize? Silently lose items? Throw? Disallow all spreads? Disallow spreads unless compiler can guarantee their length at compile time?
I think it would be constrained by all the conditions that currently allows the compiler to lower a collection expression to an inline array?
@alrz This is currently not specced, it's all compiler optimization, and the compiler silently falls back to using heap types if inline arrays aren't considered most performant to involve. The spec would need to specify how the user's experience meets this process for the first time when an inline array is required.
I'm locking this issue as all of our issues should be locked in the new repo organization; apologies that it wasn't locked already. Feel free to start a discussion to continue this topic.