C# 程序创建一个空字符串数组

csharpprogrammingserver side programming更新于 2025/9/17 9:42:00

创建一个空字符串数组 −

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...

相关文章