C# if else


If-Else语句根据您的前提条件是否已满,执行代码块。

if(boolean expression)
{
// execute this code block if expression evalutes to true
}
else
{
// always execute this code block when above if expression is false
}


int Price = 30;

If (Price = 30)
{
Console.WriteLine("Price is equal to 30.");
}

Else
{
Console.WriteLine("Price is not equal to 30.");
}

由于我们已经宣布我们的int Price为30,这将是预期的产出。

输出

Price is equal to 30.