Asp.net for each

Source: Internet
Author: User

For Each... In loop structure

The memory address of the image is extracted from the memory and received by the variable following For Each.

In the Next statement, the Next project in the set object is taken out, and the memory address is

For Each is followed by a variable until all objects in the set object are retrieved.

Outbound

<% @ Page Language = "VB" %>

<Script runat = "server">
Sub Page_Load (Sender as object, e as eventargs)
Dim strDay as string
Dim arrWeekDays () as String = {"Monday", "Tuesday ",

_
"Wednesday", "Thursday", "Friday "}

For Each strDay in arrWeekDays
Response. Write (strDay & "<br> ")
Exit
Next
  
End sub
</Script>

<Html> <body>

</Body>

This statement starts with the for keyword, followed by parentheses. Inside the brackets is an initiator.

In a condition and an iteration statement, they are all separated by semicolons. Nested statement in

Parentheses.

The following is an application example of the for statement:

 

For (int I = 0; I <= 6; I ++)

{

Response. Write ("The current value of loop variable I is:" + I. ToString

(). Trim () + "<br>");

}

② Foreach statement

This statement is used to loop through elements in a set. Array support in C #

Therefore, you can use the foreach statement to process every element in the array.

.

When using a foreach statement, first enter the foreach keyword and then parentheses.

The brackets must contain the following information: the type of elements in the set and the identifier of the elements in the set.

The name, keyword in, and set identifier. Nested statements are enclosed in parentheses.

The following is an application example of the foreach statement:

 

Int [] intArray;

IntArray = newint [6];

IntArray [0] = 0;

IntArray [1] = 1;

IntArray [2] = 2;

IntArray [3] = 3;

IntArray [4] = 4;

IntArray [5] = 5;

Foreach (int ArrayElement in intArray)

{

Response. Write ("The current value of the array variable ArrayElement is:

"+ ArrayElement. ToString (). Trim () +" <br> ");

}

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.