如何将A类的结构体(已经赋值了)传递到B类?大家说说可能的方法,谢谢!

解决方案 »

  1.   

            struct MyType
            {
                public string Name;
                public int Age;
            }        private void button1_Click(object sender, EventArgs e)
            {
                MyType type;
                type.Name = "ZengHD";
                type.Age = 27;            ShowType(type);
            }
      

  2.   

    我说的是 : 将结构体在不通类之间传递比如:
    struct XOT
    {
     string a;
     string b;
    }
    class A
    {
      ....
      struct objstruct
    //赋值操作
    ....
    }class B
    {
    //需要用到在A类中已经被赋值的结构体的值a,b
    ???????
    }
      

  3.   

    namespace WindowsApplication1
    {
        public struct XOT
        {
            public string a;
            public string b;
        }     public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }
            private void button1_Click(object sender, EventArgs e)
            {
                A clsA = new A("a", "B");
                XOT x = clsA.GetXot();            MessageBox.Show(x.a+"  " + x.b);
            }
        }    public class A
        {
            private XOT objstruct;
            public A(string a, string b)
            {
                objstruct.a = a;
                objstruct.b = b;
            }        public XOT GetXot()
            {
                return objstruct;
            }
        }
    }
      

  4.   

    楼上正解,学习ing...
    可惜我的问题复杂了些:结构体的成员变量有17个之多,(成员变量类型有两种:string型和int型),而且其值是从pgc文件的节点下读出来的.将这些值直接作参数传递困难度很大.