Using foreach on Arrays
C# 的 foreach ... in 用起來很方便呢!
--
C# also provides the foreach statement. This statement provides
a simple, clean way to iterate through the elements of an array.
For example, the following code creates an array called numbers
and iterates through it with the foreach statement:
int[] numbers = {4, 5, 6, 1, 2, 3, -2, -1, 0};
foreach (int i in numbers)
{
System.Console.WriteLine(i);
}
--
※ 發信站: 批踢踢實業坊(ptt.csie.ntu.edu.tw)
◆ From: 218.184.81.80
C_Sharp 近期熱門文章
PTT數位生活區 即時熱門文章