foreach语法结构,是C#中新增的循环机制,可以迭代集合中的每一项
示例:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Demo8
{
class Program
{
static void Main(string[] args)
{
Program pro = new Program();
pro.lay();
}
public void lay()
{
int[] num = new int[6] { 0, 1, 2, 3, 4, 5 }; //声明一个整型数组!
foreach (int temp in num) //foreach循环迭代num数组里的每一个数!
{
Console.WriteLine(temp); //分别输出0,1,2,3,4,5!
}
}
}
}
浙公网安备 33010602011771号