C# lets you execute code based on conditions.

To test a condition you use an if statement. The if statement returns true or false, based on your test:

  • The if statement starts a code block
  • The condition is written inside parenthesis
  • The code inside the braces is executed if the test is true

Example

@{var price=50;}
<html>
<body>
@if (price>30)
    {
    <p>The price is too high.</p>
    }
</body>
</html>



Practice Excercise Practice now