gpt4 book ai didi

c# - 错误4无效的表达词 'else'

转载 作者:行者123 更新时间:2023-12-03 08:14:48 25 4
gpt4 key购买 nike

帮助iv看到其他问题,但是我是C#的初学者

码:

namespace Input_Program
{
class Program
{
static void Main()
{
char Y = Console.ReadKey().KeyChar;

Console.WriteLine("Welcome to my bool program!");
Console.WriteLine("Input a NON capital y or n when told to.");

if(Y == 'y')
{
Console.WriteLine("Thank you,Please wait.....");
Console.WriteLine("You input Y");

else;
{
if(Y == 'n')
{
Console.WriteLine("You input N");
}
}
}
Console.ReadLine();
}

最佳答案

您不应该在else后面加上分号,并且错过在else之前的结束括号。

namespace Input_Program
{
class Program
{
static void Main()
{
char Y = Console.ReadKey().KeyChar;
Console.WriteLine("Welcome to my bool program!");
Console.WriteLine("Input a NON capital y or n when told to.");
if(Y == 'y')
{
Console.WriteLine("Thank you,Please wait.....");
Console.WriteLine("You input Y");
}
else
{
if(Y == 'n')
{
Console.WriteLine("You input N");
}
}
Console.ReadLine();
}
}
}

关于c# - 错误4无效的表达词 'else',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5413907/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com