c#中for循环与foreach的区别

for 你先要给初值,末值和步长

foreach 不需要事先给定初值,末值和步长,他是自动遍历给定的集合体的所有值

string[] a=new string[]{"a","b"}

for(i=0;i<a.length;i++)
{
Response.write(a[i].ToString())
}

foreach(string b in a)
{
Response.write b
}
posted @ 2011-09-04 15:55  园博客  阅读(613)  评论(0)    收藏  举报