c# 结构体中包含结构体数组的使用

c# 中定义了两个结构体,B中包含多组A

 #region 结构体A
    struct A
    {
        public int dataNum;
        public double inVol;
    };
    #endregion

    #region 结构体B
    struct B
    {
        public string s1;
        public string s2;
        public List<A> aaas;
       //public List<A> aaas=new List<A>()//这样使用报错:结构中不能有实例字段初始值设定项
    }; 
#endregion

A a=new A();
a.datanum=1;
a.inVol=1.0;

B b=new B();
//b.aaas.add(a);//直接用会报错:未将对象引用设置到对象的实例

B.aaas=new List<A>;
b.aaas.add(a);

  

原文地址:https://www.cnblogs.com/webttt/p/11971825.html