Sinex wrote:
I want to declare an array of constants (of type byte) and
initialize the array ...all at one shot. How do I do that?
As mentioned, there's no convenient built-in way to do this, but what you
can do is declare a simple class that wraps an array and only exposes the
ability to read it, like this (warning, code is untested):
class ConstArray {
byte[] data;
public ConstArray(byte[] data) {
this.data = data;
}
public byte this [int index] {
get
{
return data[index];
}
}
}
Now you can declare in your class:
public readonly ConstArray arr = new ConstArray(new byte[3] {0x01, 0x02,
0x03});
Now the compiler will enforce that neither the array nor its elements can be
changed. If possible you may want to make ConstArray a value type to avoid
unneccessary indirection.
--
Derrick Coetzee, MCP, MSFT (Speech Server)
This posting is provided "AS IS" with no warranties, and confers no
rights. Use of included code samples are subject to the terms
specified at
http://www.microsoft.com/info/cpyright.htm