ASP. NET Razor-C # loop and array, asp. netrazor
Statements can be repeatedly executed in a loop.
For Loop
To run the same statement repeatedly, you can write a loop.
If you can determine the number of cycles, you can useFor Loop. This type of loop is specifically designed for counting or reverse counting:
Instance
Running instances
For Each loop
If you need to process a set or arrayFor each loop.
A set of similar objects. A for each loop allows you to execute a task on each project. The for each loop traverses the set until it is completed.
The following example traverses the ASP. NET Request. ServerVariables set.
Instance
Running instances
While Loop
While is a general loop.
While LoopStart with the keyword while, followed by parentheses, which define the continuous length of the loop, and then the code block to be recycled.
While loops usually increase or decrease the variable used for counting.
In the following example, every time a loop is run, the + = operator adds 1 to variable I.
Instance
Running instances
Array
If you need to store similar variables but do not want to create independent variables for each project, the array will come in handy:
Instance
@{string[] members = {"Jani", "Hege", "Kai", "Jim"};int i = Array.IndexOf(members, "Kai")+1;int len = members.Length;string x = members[2-1];}
Running instances