如何在 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.