ASP.NET RazorLesson 21Free preview
Razor C# Variables
This lesson is part of ASP · All levels
Summary
This section discusses the writing of C# variables within a Razor page, ranging from the var keyword and explicit type to string manipulation as well as DateTime. The variable is declared in the @{} block and its value can be displayed with the @ sign. Understanding the data type is important so that the calculations and the display format are not wrong.
Key points
- Var is used to infer the data type from the initial value.
- Explicit types such as int, string, and decimal are used when the type is to be clear.
- Strings are limited to double quotation marks and can be combined with the + sign.
- DateTime provides properties and methods like Now, Year, and ToString.
Full lesson
Code examples and quizzes
Full lessons, code examples, and quizzes are available to subscribers. 5 questions.