使用 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
廣告
資料結構
網路
RDBMS
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP