代码改变世界

遍历数组元素FOREACH语句

  精诚所至 金石为开  阅读(360)  评论(0编辑  收藏  举报

用FOREACH语句可以遍历数组中的所有元素。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
using System;
namespace a
{
    class Program
    {
        public static void Main(string[] args)
        {
            string[] friendNames={"Robert Barwell","Mike Parry","Jeremy Beacock"};
            Console.WriteLine("Here are {0} of my friends:",friendNames.Length);
            foreach (string friendName in friendNames)
            {
                Console.WriteLine(friendName);
            }
            Console.ReadKey();
        }
    }
}
点击右上角即可分享
微信分享提示