Is there any established way of returning a read-only 2-d array in C#?
I know ReadOnlyCollection
is the right thing to use for a 1-d array, and am happy to write my own wrapper class that implements a this[] {get}
. But I don't want to reinvent the wheel if this wheel already exists.
A two-dimensional array in C can be thought of as a matrix with rows and columns. The general syntax used to declare a two-dimensional array is: A two-dimensional array is an array of several one-dimensional arrays. Following is an array with five rows, each row has three columns: int my_array[5][3];
An element in 2-dimensional array is accessed by using the subscripts. That is, row index and column index of the array. int x = a[1,1]; Console.
The basic form of declaring a two-dimensional array of size x, y: Syntax: data_type array_name[x][y]; Here, data_type is the type of data to be stored.
Unfortunately there is no any built-in implementation to handle a case you ask for. But a simple implementation on your own, shouldn't be something difficult.
The only think, I hope you aware of it, that you will do is a readonly collection, but not elements inside that collection.
Hope this helps.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With