If I wish to access the X and Y value of a Vector2 class as an Index in XNA, then I currently use the following extension:
public static float Index(this Vector2 v, int index)
{
switch (index)
{
case 0: { return v.X; }
case 1: { return v.Y; }
default:
{
// This is unsafe code BUT it is useful for debugging
throw new ArgumentOutOfRangeException(
"Vector component index out of range"
);
}
}
}
This works fine for accessing the X and Y value, but how can I set the X and Y value using this method?
for (int i = 0; i < 2; ++i)
{
// Accessing Index value works fine
v = point.Index(i);
v = Math.Max(v, min.Index(i));
v = Math.Min(v, max.Index(i));
// Setting Index value is not possible
q.Index(i) = v;
}
If this isn't possible, is there another method I can use?
Thank you.