如何修复C#中的"System.String []"错误?(使用数组+ For循环)

Tom*_*Tom 2 c# arrays loops for-loop

好吧,我正在尝试创建一个基本上使用for循环来显示一周中的日期的程序,我的代码看起来很好,运行正常,但是当我碰巧运行它...它出现了"它的日子一周是System.String []"..而我希望它显示星期几是星期一...星期几是星期二......星期三......等等.

这是我到目前为止为此编写的代码:

        //Declare variables
        int iDays;

        //Declare array
        const int iWEEK = 7;
        string[] sDays = new string[iWEEK] { "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday" };

        //Display the days of the week
        for (iDays = 0; iDays < iWEEK; iDays++)
        {
            Console.WriteLine("The day of the week is " + sDays);
        }

        //Prevent program from closing
        Console.WriteLine();
        Console.WriteLine("Press any key to close");
        Console.ReadKey();
Run Code Online (Sandbox Code Playgroud)

Jer*_*vel 6

您必须在数组内打印一个值,而不是数组本身.

使用sDays[iDays]来代替.这将检索iDays数组中位置的值sDays.