Long story short, I’ll provide a simplistic example where it might be useful:
public struct Vector3f {
public float x;
public float y;
public float z;
public unsafe float this[int index] {
get {
// Get "p" somehow, so that it points to "this"...
return p[index];
}
set {
// Get "p" somehow, so that it points to "this"...
p[index] = value;
}
}
}
I guess you got my point there:
var v = new Vector3f();
Assert(v.x == v[0]);
EDIT 1:
For those, who still ask 🙂
Assert(v.y == v[1]);
Assert(v.z == v[2]);
EDIT 2:
Does fixed create redundant overhead here?
Or maybe this struct is already fixed, and therefore fixed has no effect here and is only needed to satisfy the compiler? Possible answer.
You mean something like this?