L
lee.crabtree
In C#, an array marked 'readonly', as in:
public readonly bool[] array = new bool[8];
would allow individual members of the array to be modified while
protecting the array reference itself from being changed. That is, I
could do this:
array[0] = false;
but not this:
array = null;
However, it doesn't seem like the 'initonly' keyword in C++/CLI does
exactly the same thing. If I do something like this:
public ref class Thing
{
public:
Thing();
void SetBool();
protected:
initonly array<bool>^ bArr;
};
Thing::Thing()
{
bArr = gcnew array<bool>(8);
}
void Thing::SetBool()
{
bArr[0] = false;
}
I get a compilation error about using an 'initonly' field as an l-
value. What's the right way to go about this?
public readonly bool[] array = new bool[8];
would allow individual members of the array to be modified while
protecting the array reference itself from being changed. That is, I
could do this:
array[0] = false;
but not this:
array = null;
However, it doesn't seem like the 'initonly' keyword in C++/CLI does
exactly the same thing. If I do something like this:
public ref class Thing
{
public:
Thing();
void SetBool();
protected:
initonly array<bool>^ bArr;
};
Thing::Thing()
{
bArr = gcnew array<bool>(8);
}
void Thing::SetBool()
{
bArr[0] = false;
}
I get a compilation error about using an 'initonly' field as an l-
value. What's the right way to go about this?