C# CS1513错误}应为

C# CS1513错误}应为,c#,C#,在visualstudios用C编写的以下代码中,我不断收到一个CS1513错误# { 非十二生肖类 { 静态void Main(字符串[]参数) { 一岁出生; 国际年博宁; WriteLine(“你出生的年份是什么?”); YearBorn=Console.ReadLine(); YearBornInt=转换为32(YearBorn); WriteLine(“您是”+(DateTime.Now.Year-YearBornInt)); 如果((DateTime.Now.Year-YearBor

在visualstudios用C编写的以下代码中,我不断收到一个CS1513错误#

{
非十二生肖类
{
静态void Main(字符串[]参数)
{
一岁出生;
国际年博宁;
WriteLine(“你出生的年份是什么?”);
YearBorn=Console.ReadLine();
YearBornInt=转换为32(YearBorn);
WriteLine(“您是”+(DateTime.Now.Year-YearBornInt));
如果((DateTime.Now.Year-YearBornInt)<18);
控制台。写线(“你不能通过”);
其他的
控制台。写线(“请继续”);
Console.ReadLine();//最后一个回车键

有人看到我的错误吗???

您用分号终止了此行:

if ((DateTime.Now.Year - YearBornInt) < 18);
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)
控制台。写线(“你不能通过”);
其他的
控制台。写线(“请继续”);
或者为了更好的可读性

if ((DateTime.Now.Year - YearBornInt) < 18)
{
     Console.WriteLine("You Shall Not PASS");
}
else
{
     Console.WriteLine("Please Proceed");
}
if((DateTime.Now.Year-YearBornInt)<18)
{
控制台。写线(“你不能通过”);
}
其他的
{
控制台。写线(“请继续”);
}

if-else之间不允许有空格。yes..删除if((DateTime.Now.Year-YearBornInt)<18)的结尾分号@m.kudi您可以在
if
else
之间有空行或注释行,但它们之间不能有多个代码块,这里就是这种情况。我不同意为if和else语句添加花括号可以增加单行语句的可读性。欢迎您不同意。对我来说,这是一个标记it’很明显什么是属于if/else的,避免了不必要的错误。这取决于您或您的公司以不同的方式处理它。
if ((DateTime.Now.Year - YearBornInt) < 18)
{
     Console.WriteLine("You Shall Not PASS");
}
else
{
     Console.WriteLine("Please Proceed");
}