C# works on the base of types, Array
's represent a non-readonly collection, so the following:
Now, the subset only needs to be read only.
Can't be implemented without changing type accepted by the method. Depending on the case you can consider using either ReadOnlySpan<T>
or ReadOnlyMemory<T>
which were designed for such cases.
Note that arrays in C# are not "just pointers" to some block of memory, they are objects with quite specific structure (see the Managed object internals, Part 3. The layout of a managed array article). If method signature can't be changed you can try leveraging this fact (on your own risk of course, since this structure is