初始化建構函式中定義的實體集合,方便巢狀型別的遍曆

來源:互聯網
上載者:User

標籤:color   har   inf   構造   int   遍曆   item   集合   定義   

class Programs    {        public static void OP()        {            Student[] stuinfo = new Student[]             {                  new Student("HB001","Tom",‘男‘,20,new List<Archement>(new Archement[]{new Archement("HB001","大學數學",88),new Archement("HB001","大學語文",88)})),                new Student("HB002","Lucy",‘女‘,23,new List<Archement>(new Archement[]{new Archement("HB002","大學數學",88),new Archement("HB002","大學語文",88)})),                new Student("HB003","Peter",‘男‘,27,new List<Archement>(new Archement[]{new Archement("HB003","大學數學",88),new Archement("HB003","大學語文",88)})),                new Student("HB004","Bruce",‘男‘,30,new List<Archement>(new Archement[]{new Archement("HB004","大學數學",88),new Archement("HB004","大學語文",88)}))            };            foreach (var item in stuinfo)            {                Console.WriteLine("{0}\t{1}\t{2}\t{3}", item.StuID, item.StuName, item.StuSex, item.Age);                foreach (var s in item.Score)                {                    Console.WriteLine("{0}\t{1}", s.CourseName, s.Score);                }            }                  }    }    public class Student    {        public string StuID { get; set; }        public string StuName { get; set; }        public char StuSex { get; set; }        public uint Age { get; set; }        public List<Archement> Score { get; set; }        public Student(string ID, string Name, char Sex, uint Uage, List<Archement> lst)        {            this.StuID = ID;            this.StuName = Name;            this.StuSex = Sex;            this.Age = Uage;            Score = new List<Archement>();            foreach (var item in lst)            {                this.Score.Add(item);            }        }    }    public class Archement    {        public string StuNo { get; set; }        public string CourseName { get; set; }        public double Score { get; set; }        public Archement(string ID, string Name, double DScore)        {            this.StuNo = ID;            this.CourseName = Name;            this.Score = DScore;        }    }

 

初始化建構函式中定義的實體集合,方便巢狀型別的遍曆

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.