c#遍历数组

来源:互联网 发布:图书管理数据库er图 编辑:程序博客网 时间:2024/06/05 12:39

c#中,我们可以使用一个for循环来访问每个数组元素,也可以使用foreach'语句来遍历数组

using System;

namespace ArrayApplication

{

class MyArray

{

static void Main(string[] args)

{

int [] n=new int [10];

for (int i=0;i<10;i++)

{

n[i]=i+100;

}

foreach(int j in n)

{

int i=j-100;

Console.WriteLine("Element[{0}]={1}",i,j);

}

Console.ReadKey();

}

}

}

1 0
原创粉丝点击