使用 for 循环迭代字符串数组的 C# 程序


创建一个字符串数组——

string[] str = new string[] {
   "Videos",
   "Tutorials",
   "Tools",
   "InterviewQA"
};

循环直到数组的长度——

for (int i = 0; i < str.Length; i++) {
   string res = str[i];
   Console.WriteLine(res);
}

以下是完整代码——

示例

 活动演示

using System;

public class Demo {
   public static void Main() {
      string[] str = new string[] {
         "Videos",
         "Tutorials",
         "Tools",
         "InterviewQA"
      };
   
      Console.WriteLine("String Array...");
      for (int i = 0; i < str.Length; i++) {
         string res = str[i];
         Console.WriteLine(res);
      }
   }
}

输出

String Array...
Videos
Tutorials
Tools
InterviewQA

更新日期: 22-Jun-2020

2K+ 查看

启动你的职业生涯

通过完成课程获得认证

开始
广告
© . All rights reserved.