如果我有:
class Test
{
private Vector2 v;
public Vector2 Velocity
{
get { return v; }
set { v = value; }
}
}
接着:
Test t = new Test();
t.Velocity = new Vector2(2, 2);
t.Velocity.Normalize();
Console.WriteLine(t.Velocity); // here not normalized
Vector2 tmp = t.Velocity;
tmp.Normalize();
t.Velocity = tmp;
Console.WriteLine(t.Velocity); // here normalized
Console.Read();
为什么如果我直接尝试在属性 Velocity 上调用 Normalize 它没有被规范化并且使用 tmp Vector2 它是?
PS Vector2 是一个结构:
public struct Vector2 : IEquatable<Vector2>
{
public float X;
public float Y;
...
public void Normalize() {...}
}