• C# code blocks are enclosed in @{ ... }
  • Inline expressions (variables or functions) start with @
  • Code statements end with semicolon
  • Variables are declared with the var keyword, or the datatype (int, string, etc.)
  • Strings are enclosed with quotation marks
  • C# code is case sensitive
  • C# files have the extension .cshtml

C# Example

<!-- Single statement block -->
@{ var myMessage = "Hello World"; }

<!-- Inline expression or variable -->
<p>The value of myMessage is: @myMessage</p>

<!-- Multi-statement block -->
@{
var greeting = "Welcome to our site!";
var weekDay = DateTime.Now.DayOfWeek;
var greetingMessage = greeting + " Today is: " + weekDay;
}
<p>The greeting is: @greetingMessage</p>



Practice Excercise Practice now