Can you have a Constant Array in C#

  • Thread starter Thread starter News VS.NET \( MS ILM \)
  • Start date Start date
N

News VS.NET \( MS ILM \)

hello,

how do you declare a multi-dimentional constant array in C#
does this make sense?

Thanks
 
Can you be a little more specific. If you want a multi dimensional
array, you can do this:

// Create a multi dimensional array.
int[,] pintArray = new int[2, 2];

This is different than a jagged array, which is like this:

int[][] pintArray = {new int[2], new int[2]};

Hope this helps.
 
how do you declare a multi-dimentional constant array in C#
does this make sense?

No, arrays can't be constant. You can store an array reference in a
static read-only field, but that will only prevent the reference from
being modified, not the content for the array being referred to.



Mattias
 
From what I can tell, the only thing that can be constant in C# is instance
variables. Supposedly C# is safer than C++. Not that I believe that
farther than you can throw a house-sized boulder.
 
Hi NoName,

Yes. In effect.

Create a static class which contains your array.
Give the class read-only indexer properties.

What do you want these constant arrays for ?

Regards,
Fergus
 
Back
Top