“else”无法开始声明。[杂项文件.csproj]

0 c#

我是编程新手(C#),我的代码说我使用的 if else 语句导致了错误。我不知道这有什么问题。有人能帮助我吗?

    if(ItemPrice==Soda);
    {
        Console.WriteLine($"Inserted so far: P0 out of P{Soda}");
        break;
    }
    else if(ItemPrice==Juice);
    {
        Console.WriteLine($"Inserted so far: P0 out of P{Juice}");
    }
    else if(ItemPrice==WaterBottle);
    {
        Console.WriteLine($"Inserted so far: P0 out of P{WaterBottle}");
    }
Run Code Online (Sandbox Code Playgroud)

AAA*_*ddd 7

;if 语句后有分号 ( ),它会给出这些警告

编译器警告(3 级)CS0642

可能错误的空语句

条件语句后面的分号可能会导致代码的执行与预期不同。

还有这个错误

编译器错误 CS1513

}预期的

编译器需要一个右花括号 ( }),但未找到。

您需要的语法

if (condition) 
{
   // statement;
}
else if (condition) 
{
   // statement;
}
else if (condition) 
{
   // statement;
}
Run Code Online (Sandbox Code Playgroud)

其他资源

if-else(C# 参考)