.NET基礎--數組

            int []score=new int[5];
            score[0] = 70;
            score[1] = 75;
            score[2] = 88;
            score[3] = 96;
            score[4] = 82;

            foreach (int i in score)
            {
                Console.WriteLine(i);
            }

            Console.WriteLine("for循環");

            for (int i = 0; i < score.Length; i++)
            {
                Console.WriteLine(score[i]);
            }
            Console.ReadLine();<span style="font-family: Arial, Helvetica, sans-serif; background-color: rgb(255, 255, 255);">			</span><span style="font-family: Arial, Helvetica, sans-serif; background-color: rgb(255, 255, 255);">			</span>

數組聲明語法:

數據類型[] 數組名=new 類型[數組長度];

Int[] score=new int[5] //C語言的數組是 int score[]=new int[5];不要與C#的數組搞混了

通過score.length可顯示出數組的長度


可以通過for和foreach來遍歷數組。foreach使用的時候,不用知道數組的長度。


     

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章