使用 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.