foreach的使用

直接访问数组每一个数

 1 using System;
 2 namespace ArrayApplication
 3 {
 4     class MyArray
 5     {
 6         static void Main(string[] args)
 7         {
 8             int[] n = new int[10];
 9             int i;
10             for(i=0;i<10;i++)
11             {
12                 n[i] = i + 100;
13             }
14             foreach(int j in n)
15             {
16                
17                 Console.WriteLine("{0}",  j);
18 
19             }
20             Console.ReadKey();
21 
22             
23         }
24     }
25 }

 

posted @ 2021-09-17 00:18  welasss  阅读(39)  评论(0)    收藏  举报