C# foreach的详细用法

2025-02-24 20:53:00
推荐回答(2个)
回答1:

就是循环遍历一个数组,比如:
int[] a = new int[100];
for(int i=0;ia[i] = i;

}

foreach(int item in a){
Console.WriteLine(item);

}

参考微软官方文档:http://technet.microsoft.com/zh-cn/magazine/ttw7t8t6.aspx

回答2:

foreach(Type t in arrys)
{
//..do your things
}
Type:需要遍历每一个的对象的类型
t:每一个对象
arrays:需要遍历的对象数组