0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

for文とforeach文で配列の要素をすべて表示させる

Last updated at Posted at 2020-01-18
class Program
{
    
    static void Main(string[] args)
    {
        string[] array = {"月曜日", "火曜日", "水曜日", "木曜日", "金曜日", "土曜日", "日曜日" };

        //arrayの要素数を表示
        Console.WriteLine(array.Length);

        Console.WriteLine("");

        //要素数の数だけ繰り返す
        for (int i = 0;i <array.Length;i++)
        {
            Console.WriteLine(array[i]);
        }

        Console.WriteLine("");

        //foreachで要素数の数だけ繰り返す
        foreach (string a in array)
        {
            Console.WriteLine(a);
        }

    }
}

【結果】

7

月曜日
火曜日
水曜日
木曜日
金曜日
土曜日
日曜日

月曜日
火曜日
水曜日
木曜日
金曜日
土曜日
日曜日
0
1
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?