当前位置:编程学习 > C#/ASP.NET >>

net c# 数组循环的用法 foreach 和 for循环

static void Main(string[] args)
        {
            String[] str =new string[]{"Do","you","like","C#"};
            Console.WriteLine("用foreach:");
            foreach (string s in str)
            {
                Console.WriteLine(s);
            }
 
            Console.WriteLine("\n不用foreach 語句,用for :");
            //效果与foreach 的一样
           for (int i = 0; i < str.Length; i++)
            {
                Console.WriteLine(str[i]);
            }

CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,