C#程序使用for循环遍历字符串数组
创建一个字符串数组-
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