M
Michel Andr?
Whats the reasoning for not being able to instantiate const arrays in
C# or have I missed something
void Foo()
{
const int i = 0;
const string str = "s";
// error CS0133: The expression being assigned to 'intArray' must be
constant
const int[] intArray = { 1,2,3 };
const string[] strArray = { "1","2","3" };
}
My solutin which isn't as elegant is to use at class scope
static readonly string[] _strArray = { "1","2","3" };
I can't reinitialize the array but _strArray[0] will change the
contents.
This is easy enough to do in C++ eg.
Regards
/m
C# or have I missed something
void Foo()
{
const int i = 0;
const string str = "s";
// error CS0133: The expression being assigned to 'intArray' must be
constant
const int[] intArray = { 1,2,3 };
const string[] strArray = { "1","2","3" };
}
My solutin which isn't as elegant is to use at class scope
static readonly string[] _strArray = { "1","2","3" };
I can't reinitialize the array but _strArray[0] will change the
contents.
This is easy enough to do in C++ eg.
Regards
/m