ASP. NET Razor-C # loop and array, asp. netrazor

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.