CS1513错误}预期
本文关键字:预期 错误 CS1513 | 更新日期: 2023-09-27 18:13:08
我一直在visual studio中使用c#编写以下代码时出现CS1513错误
{
class NotChineseZodiac
{
static void Main(string[] args)
{
String YearBorn;
int YearBornInt;
Console.WriteLine("What was the year of your birth?");
YearBorn = Console.ReadLine();
YearBornInt = Convert.ToInt32(YearBorn);
Console.WriteLine("You are" + (DateTime.Now.Year - YearBornInt));
if ((DateTime.Now.Year - YearBornInt) < 18);
Console.WriteLine("You Shall Not PASS");
else
Console.WriteLine("Please Proceed");
Console.ReadLine(); // last enter key
有人看到我的错误吗?
这一行用分号结束:
if ((DateTime.Now.Year - YearBornInt) < 18);
正确应该是:
if ((DateTime.Now.Year - YearBornInt) < 18)
Console.WriteLine("You Shall Not PASS");
else
Console.WriteLine("Please Proceed");
或者为了更好的可读性
if ((DateTime.Now.Year - YearBornInt) < 18)
{
Console.WriteLine("You Shall Not PASS");
}
else
{
Console.WriteLine("Please Proceed");
}