在同一个命名空间下有几个类,我想在一个类中调用另一个类中已经初始化了的结构体,该怎么办?

解决方案 »

  1.   

    将该结构体设为public static
      

  2.   

    用属性来实现
    http://blog.csdn.net/knight94/archive/2006/06/04/772886.aspx
      

  3.   

    在初始化结构体对象的类中,把其对象设置为public的就好了。
      

  4.   

    whq1982() :将该结构体设为public static
    Knight94(愚翁) : 用属性来实现
    ==================================
    帮你实现一下就明白了:class A
    {
        String name = B.yourStruct.Name; //调用咯
    }class B
    {
        private static customStruct yourStruct;
        
        public B() { yourStruct = new CustomStruct("kevin"); }
    }struct CustomStruct
    {
        private name;
        public Name
        { 
           get { return this.name;  }
           set { this.name = value; }
        }
        
        public CustomStruct(string n) { this.Name = n; }
    }
      

  5.   

    吆!!!! B忘记用属性了
    class B
    {
        private static customStruct yourStruct;    public customStruct YourStruct
        {
           get { return this.yourStruct;  }
           set { this.yourStruct = value; }
        }    public B() { yourStruct = new CustomStruct("kevin"); }
    }