Home Python C Language C ++ HTML 5 CSS Javascript Java Kotlin SQL DJango Bootstrap React.js R C# PHP ASP.Net Numpy Dart Pandas Digital Marketing

ASP.NET Rozor C# Variables:


let's simplify C# variables in the context of ASP.NET Razor.

In ASP.NET Razor, C# variables are used to store and manipulate data within your Razor views (.cshtml files). These variables hold values that can be used to dynamically generate content on your web pages.

Here's a simple explanation with an example:

Example

@{
// Declare and initialize variables
string greeting = "Hello"; // A string variable to hold a greeting message
int age = 25; // An integer variable to hold a person's age
double pi = 3.14; // A double variable to hold the value of Pi
bool isStudent = true; // A boolean variable to indicate whether someone is a student or not

// Output variables
<p>@greeting, I am @age years old.</p>
<p>The value of Pi is approximately @pi.</p>
@if (isStudent)
{
<p>I am a student.</p>
}
else
{
<p>I am not a student.</p>
}
}

In this example:

When the Razor view is rendered, the C# code is executed on the server, and the resulting HTML is sent to the client's browser. This allows you to create dynamic web pages that can adapt to different scenarios based on the values of variables.


Advertisement
Advertisement





Q3 Schools : India


Online Complier

HTML 5

Python

java

C++

C

JavaScript

Website Development

HTML

CSS

JavaScript

Python

SQL

Campus Learning

C

C#

java