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);

  


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM