Suppose I have a multidimentional array
int[,] mdim
With a regular array int[] arr, I can do Array.AsReadOnly(arr) to get a readonly wrapper to protect my inner data when exposing outside of my class.
I'd like to be able to do the same with my multidimensional array: Array.AsReadOnly(mdim)
I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label.
Tagging subscribers to this area: @eiriktsarpalis, @jeffhandley
See info in area-owners.md if you want to be subscribed.
@hawkerm This is a nice coincidence 馃槃
Would this issue you're having be solved by using ReadOnlyMemory2D<T> and ReadOnlySpan2D<T> from the Microsoft.Toolkit.HighPerformance package (https://github.com/windows-toolkit/WindowsCommunityToolkit/pull/3353)?
As in:
int[,] array = ...; // Something
ReadOnlyMemory2D<int> memory = array;
// Use the memory or the span from there where needed
Note: I know it's not exactly the same as this wouldn't be a normal ReadOnlyCollection<T> instance, but at the same time it would also retain more info about the inner layout of the wrapped data. Not suggesting this as a definitive solution for the issue but I'm mostly just curious to know whether those APIs would be useful in this situation 馃槉
As @Sergio0694 mentioned we would probably need a dedicated type that is separate from ReadOnlyCollection<T>, presumably something that implements multi-dimensional indexers.
Most helpful comment
I believe that this request belongs on CoreCLR or CoreFX as this doesn't involve changes to the C# language but instead adding new overloads to the
Arrayclass to support multidimensional arrays.