Tạo một mảng chuỗi -
string[] str = new string[] {
"Videos",
"Tutorials",
"Tools",
"InterviewQA"
}; Lặp lại cho đến khi độ dài của mảng -
for (int i = 0; i < str.Length; i++) {
string res = str[i];
Console.WriteLine(res);
} Đây là mã hoàn chỉnh -
Ví dụ
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);
}
}
} Đầu ra
String Array... Videos Tutorials Tools InterviewQA