Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Read only two-dimensional array in C#

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.

like image 574
sblom Avatar asked Apr 18 '12 21:04

sblom


People also ask

What is the 2-dimensional array in C?

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];

How do you access 2D array elements?

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.

Which is syntax for 2-dimensional array?

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.


1 Answers

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.

like image 123
Tigran Avatar answered Sep 27 '22 21:09

Tigran