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)
;if 语句后有分号 ( ),它会给出这些警告
可能错误的空语句
条件语句后面的分号可能会导致代码的执行与预期不同。
还有这个错误
}预期的编译器需要一个右花括号 (
}),但未找到。
您需要的语法
if (condition)
{
// statement;
}
else if (condition)
{
// statement;
}
else if (condition)
{
// statement;
}
Run Code Online (Sandbox Code Playgroud)
其他资源