Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C#, how to handle constant tables

Tags:

c#

constants

It seems strange that the language apparently includes no suitable functionality.

I find myself with data that would best be expressed as a multi-dimensional array but it's utterly constant, there is no way anyone could want to change it without also changing the associated code. Faced with such stuff in Delphi the answer is obvious--a constant whose value is the table. However, C# doesn't seem to support anything like this.

Google shows many people griping about this, no good answers.

How do people handle this sort of situation?

(And don't say that constants don't belong in code--the last one I bumped into was all possible permutations of 4 items. Unless the very nature of spacetime changes this is set in stone.)

What happened?? There was an answer that came pretty close, I was asking about a detail and it vanished! Simply declaring an array sort of does the job--the only problem is that the array allocation is going to run every time. The one in front of me contains 96 values--how do I get it to initialize only once? Do I just have to accept scoping it far wider than it should be? (As it stands it's in one 3-line routine that's inside what amounts to an O(n^3) routine.)

like image 345
Loren Pechtel Avatar asked Sep 03 '09 23:09

Loren Pechtel


1 Answers

ReadOnlyCollection

like image 111
recursive Avatar answered Oct 05 '22 01:10

recursive