遍历数组
namespace 遍历数组
{
class Program
{
static void Main(string[] args)
{
int[] data = {1, 2, 3, 4, 5};
//for (int i = 0; i < data.Length; i++)
//{
// Console.WriteLine(data[i]);
//}
//int i = 0;
//while (i<data.Length)
//{
// Console.WriteLine(data[i]);
// i++;
//}
foreach (int temp in data) //foreach会依次取到数组中的值,然后赋值给temp,然后执行循环体,foreach只能取到值,不能取到索引
//,需要用到索引的话,可以使用for while
{
Console.WriteLine(temp);
}
Console.ReadKey();
}
}
}