C
cronusf
I have a matrix class of a fixed size, and I was cacheing some special
matrices as readonly:
public static readonly Matrix Zero = new Matrix(0.0f, 0.0f, 0.0f,
0.0f,
0.0f, 0.0f,
0.0f, 0.0f,
0.0f, 0.0f,
0.0f, 0.0f,
0.0f, 0.0f,
0.0f, 0.0f);
public static readonly Matrix Identity = new Matrix(1.0f,
0.0f, 0.0f, 0.0f,
0.0f,
1.0f, 0.0f, 0.0f,
0.0f,
0.0f, 1.0f, 0.0f,
0.0f,
0.0f, 0.0f, 1.0f);
However, I noticed if I did something like:
Matrix V = Matrix.Identity;
and then proceed to modify the elements of V, I also modify Identity.
This seems like an easy way to get around the "readonly" property.
Should the compiler be catching this problem?
matrices as readonly:
public static readonly Matrix Zero = new Matrix(0.0f, 0.0f, 0.0f,
0.0f,
0.0f, 0.0f,
0.0f, 0.0f,
0.0f, 0.0f,
0.0f, 0.0f,
0.0f, 0.0f,
0.0f, 0.0f);
public static readonly Matrix Identity = new Matrix(1.0f,
0.0f, 0.0f, 0.0f,
0.0f,
1.0f, 0.0f, 0.0f,
0.0f,
0.0f, 1.0f, 0.0f,
0.0f,
0.0f, 0.0f, 1.0f);
However, I noticed if I did something like:
Matrix V = Matrix.Identity;
and then proceed to modify the elements of V, I also modify Identity.
This seems like an easy way to get around the "readonly" property.
Should the compiler be catching this problem?