c#foreach循环
Given an integer array and we have to print its elements using "foreach loop" in C#.
给定一个整数数组,我们必须在C#中使用“ foreach循环”打印其元素 。
Syntax for foreach loop:
foreach循环的语法:
foreach (element in iterable-item)
{
// body of foreach loop
}
Program:
程序:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp1
{
class Program
{
static void Main(string[] args)
{
int[] data = { 12, 45, 67, 879, 89 };
foreach(int item in data)
{
Console.WriteLine(item);
}
Console.ReadKey();
}
}
}
Output
输出量
12
45
67
879
89
翻译自: https://www.includehelp.com/dot-net/printing-an-integer-array-using-foreach-loop.aspx
c#foreach循环