如何在 C# 中声明一个空的字符串数组?


在 C# 中,你可以使用字符串作为字符数组,然而,更常见的做法是使用 string 关键字来声明字符串变量。string 关键字是 System.String 类的别名。

要声明一个空字符串。

string[] arr = new string[] {}; // empty string

现在让我们看看当我们打印此空字符串时会发生什么。

示例

 现场演示

using System;

namespace Demo {

   class Program {

      static void Main(string[] args) {

         string[] arr = new string[] {}; // empty string

         string res = String.Join(" ", arr);
   
         // let us now print the empty string
         Console.WriteLine("This won't print any message since its an empty string {0}", res);
      }
   }
}

输出

This won't print any message since its an empty string

更新于:2020 年 6 月 20 日

2K+ 浏览量

开启你的 职业生涯

完成课程即可获得认证

开始
广告
© . All rights reserved.