foreach

foreach基本語法:c#

在Java中:數組

先定義數組,spa

for(數據類型  變量名 : 數組名){3d

System.out.print(變量名);code

}blog

 1 public class foreach {
 2 
 3     public static void main(String[] args) {
 4         String[] str = {"1","a","2","b","3","c","4","d","5","e","6","f"};
 5         
 6         for(String strs : str) {
 7             System.out.print(strs + " ");
 8         }
 9         
10     }
11 
12 }

運行結果:ip

JavaScript中foreach的語法:it

for(數據類型  變量名 in  數組名){class

document.write(數組名[變量名]);變量

}

1 <script>
2     var i = new Array("abc","def","ghi");
3     
4     for(var a in i){
5         document.write(i[a] + " ");
6     }
7     
8 </script>

運行結果:

c#中foreach的語法:

foreach(數據類型  變量名 in  數組名){

 

}

因電腦緣由,因此c#的代碼與運行結果沒法展現

相關文章
相關標籤/搜索