C#中数组的使用

1.for

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Demo
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] friendNames = { "张三","李四","王五" };
            int i;
            Console.WriteLine("我有{0}个朋友!",friendNames.Length);
            for (i = 0;i<friendNames.Length;i++)
            {
                Console.WriteLine(friendNames[i]);
            }

            Console.ReadKey();
        }
    }
}

2.foreach

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Demo
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] friendNames = { "张三","李四","王五" };
            Console.WriteLine("我有{0}个朋友!",friendNames.Length);
            
            foreach(string friendName in friendNames)
            {
                Console.WriteLine(friendName);
            }

            Console.ReadKey();
        }
    }
}

posted @ 2017-04-18 16:52  TBHacker  阅读(1032)  评论(0编辑  收藏  举报