Currently, my code resembles this:
private static readonly int[] INTARRAY = {1, 2, 3};
This prevents me from assigning to INTARRAY to a new instance of int[] outside of the static constructor, but it still allows me to assign to the individual int elements.
For example:
INTARRAY[1] = 5;
How can I make this array completely read-only? This is an array of value-types, and is assigned with an array initializer in the declaration. How can I make these initial values persist indefinitely?
If it’s an array, you can’t. But if you’re willing for it to be an
IList<int>, you can do: