public double Magnitude
        {
            get
            {
                return Math.Sqrt(this.SumComponentSqrs());
            }
            set
            {
                if (value < 0.0)
                {
                    throw new ArgumentOutOfRangeException("value", value, "The magnitude of a Vector3 must be a positive value, (i.e. greater than 0)");
                }
                if (this == new Vector3(0.0, 0.0, 0.0))
                {
                    throw new ArgumentException("Cannot change the magnitude of Vector3(0,0,0)", "this");
                }
                this = (Vector3) (this * (value / this.Magnitude));
            }这个代码的诡异之处是Magnitude自己给自己赋值了
但是,我看了2天代码,包括子程序和主程序
都没有其他外在程序给Magnitude赋值的语句
例如:object.Magnitude=x
等等诸如语句,什么都没有
难道,Magnitude能自我迭代自己?是错的吧!?
其中this 就是Vector3c#

解决方案 »

  1.   

    set里的value / this.Magnitude
    会去访问get,因此那个地方等价于
    value / Math.Sqrt(this.SumComponentSqrs()); 如果是迭代调用属性自己反而错了(比如get里访问属性值,set里再给属性本身赋值),死循环,堆栈直接溢出
    但是你上面那个不是的,get:每次访问this.Magnitude,都会进行那个运算
      

  2.   

    谢谢,dongxinxi
    你水平真高
    简单一句话,让我有点明白了
    我在研究下和大家交流
      

  3.   

    是不是说,get和set之间一旦发生迭代调用就会错误?
    就算错误怎么才能实现迭代呢?