创建一个空字符串数组-
string[] str = new string[] {};
上面,我们没有向数组中添加元素,因为它是空的。
即使我们循环遍历数组,它也不会显示任何内容,如下所示:
using System; public class Demo { public static void Main() { string[] str = new string[] {}; Console.WriteLine("String Array elements won't get displayed since it's empty..."); for (int i = 0; i < str.Length; i++) { string res = str[i]; Console.WriteLine(res); } } }
输出结果
String Array elements won't get displayed since it's empty...