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 }
转载于:https://www.cnblogs.com/rocfly/archive/2011/09/04/2166497.html