Begtostudy(白途思)'s Professional Technology Blog

欢迎访问begtostudy的专业知识博客!主要是专业技术和算法为主。
  首页  :: 联系 :: 订阅 订阅  :: 管理

使用Ironpython,怎么也没办法给结构体赋值。

[Serializable]
    public struct Matrix3x3
    {
        public double Xx;
        //
        public double Xy;
        //
        public double Xz;
        //
        public double Yx;
        //
        public double Yy;
        //
        public double Yz;
        //
        public double Zx;
        //
        public double Zy;
        //
        public double Zz;

        public override string ToString();
    }

  

  element1=Matrix3x3()
            element1.Xx = X.X
            element1.Xy = X.Y
            element1.Xz = X.Z
            element1.Yx = Y.X
            element1.Yy = Y.Y
            element1.Yz = Y.Z
            element1.Zx = Z.X
            element1.Zy = Z.Y
            element1.Zz = Z.Z
            theUI.NXMessageBox.Show("Error", NXMessageBox.DialogType.Warning,X.X.ToString())  
            theUI.NXMessageBox.Show("Error", NXMessageBox.DialogType.Warning,element1.Xx.ToString())  

theUI.NXMessageBox.Show("Error", NXMessageBox.DialogType.Warning,str(type(X.X)))   
  theUI.NXMessageBox.Show("Error", NXMessageBox.DialogType.Warning,str(type(element1.Xx)))  

  

X.X.ToString()为实数,但是element1.Xx.ToString()始终为0
两者类型都是<float>

害得我搞了一上午和一下午,人生能有多少个白天啊!!!
最终终于在stackoverflow上走到了类似的帖子:
http://stackoverflow.com/questions/2664381/how-to-handle-value-types-when-embedding-ironpython-in-c

改成下面这样就好了:

            element1=Matrix3x3(Xx = X.X,Xy = X.Y,Xz = X.Z,Yx = Y.X,Yy = Y.Y,Yz = Y.Z,Zx = Z.X,Zy = Z.Y,Zz = Z.Z)

  

原来,值类型的属性必须要在构造函数里赋值,否则拿到的就是副本!!!!

太没天理了啊!



前往Begtostudy的编程知识博客(CSDN)