c#部分---結構體;

來源:互聯網
上載者:User

標籤:

結構體:自訂類型 實值型別
一組變數的組合
需要定義的位置 class裡面 main函數外面
裡麵包含的變數可以是多種資料類型的

 

例如學生資訊的結構體:學號,姓名,性別,分數

 struct Student        {            public int xuehao;            public string name;            public string sex;           public double score;        }//執行個體化結構體            //Student st = new Student();            //st.xuehao = 1001;            //st.name = "張三";            //st.sex = "男";            //st.score = 33;            //Student st1 = new Student();            //st1.xuehao = 1002;            //st1.name = "李四";            //st1.sex = "女";            //st1.score = 44;

還可以把分數再細分為語文成績,數學成績,英語成績

  struct Student        {            public int xuehao;            public string name;            public string sex;            public Score score;        }        struct Score        {            public double yufen;            public double shufen;            public double yingfen;        } //ArrayList al = new ArrayList();            //Console.Write("請輸入班級人數:");            //int a = int.Parse(Console.ReadLine());            //for (int i = 0; i < a;i++ )            //{            //    Student sst = new Student();            //    Console.Write("請輸入第{0}個學生的學號:",(i+1));            //    sst.xuehao = int.Parse(Console.ReadLine()) ;            //    Console.Write("請輸入第{0}個學生的姓名:", (i + 1));            //    sst.name = Console.ReadLine();            //    Console.Write("請輸入第{0}個學生的性別:", (i + 1));            //    sst.sex = Console.ReadLine();            //    Console.Write("請輸入第{0}個學生的分數:", (i + 1));            //    sst.score = double.Parse(Console.ReadLine());            //    al.Add(sst);            //}            //Console.WriteLine("所有人員資訊輸入完畢!請按斷行符號鍵開始列印!");            //Console.ReadLine();            //for (int i = 0; i < al.Count;i++ )            //{            //    Student sst = (Student)al[i];            //    Console.WriteLine("第{0}個學生的學號是:{1},姓名是{2},性別是{3},分數是{4}。",(i+1),sst.xuehao,sst.name,sst.sex,sst.score);            //}            ////執行個體化            //Student st = new Student();            //st.score.yufen = 77;            //st.score.shufen = 88;            //st.score.yingfen = 99;

 

c#部分---結構體;

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.