好吧,我正在尝试创建一个基本上使用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) 好的,我已经将一个基本的二进制转换器变成了十进制,我正在尝试验证用户输入,因此它只能是0或1,这在第一次工作正常,如果他们输入的值不正确它要求他们重新输入它,但是如果他们第二次输入错误值就会出现问题,我怎么会碰巧解决这个问题呢?或者喜欢将它循环回程序的特定部分?非常感谢,这是我的代码:
if (iBinaryNum1 == 1 || iBinaryNum1 == 0)
{
Console.WriteLine("The binary value entered for integer 1 is correct");
}
else
{
Console.WriteLine("The binary value entered for integer 1 is incorrect");
Console.WriteLine("Please Re-enter this value");
iBinaryNum1 = Convert.ToInt32(Console.ReadLine());
}
Run Code Online (Sandbox Code Playgroud)