A variable is a named entity used to store data.
Variable
Variables are used to store data.
The variable name must begin with an alphabetic character and cannot contain spaces and reserved characters.
A variable can be a specific type that indicates the type of data it stores. String variables Store string values ("Welcome to W3school"), integer variables store numeric values (103), date variables store date values, and so on.
Variables are declared using the var keyword or type, but ASP. NET is usually able to determine the type of the data automatically.
Use var keyword: var greeting = "Welcome to W3school"; var counter = 103;var today = datetime.today;//using the data type: string greet ing = "Welcome to W3school"; int counter = 103;datetime today = Datetime.today;
Statements can be repeated in a loop.
For loop
If you need to run the same statement repeatedly, you can write a loop.
If you are able to determine the number of cycles, you can use the for loop . This type of loop is designed specifically for counting or reverse counting:
For Each loopIf you need to work with collections or arrays, you typically use the For each loop .
A collection is a set of similar objects that allow you to perform a task once on each project. The For Each loop iterates through the collection until it is finished.
The following example iterates through the ASP. NET Request.ServerVariables collection.
While loopWhile is a general-purpose loop.
The while Loop begins with the keyword while, followed by parentheses, which defines the length of the loop, and then the block of code to loop.
The while loop usually increases or decreases the variable used for the count.
In the following example, each time the loop is run, the + = operator adds 1 to the variable i.
@{string[] Members = {' Jani ', ' hege ', ' Kai ', ' Jim '};int i = array.indexof (members, ' Kai ') +1;int len = members. Length;string x = members[2-1];}
ArrayIf you need to store similar variables, but you don't want to create separate variables for each project, then the array comes in handy:
ASP. NET MVC Razor Syntax (2)