C# 程序使用 for 循环遍历字符串数组
csharpprogrammingserver side programming更新于 2025/9/17 9:21:00
创建字符串数组 −
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

