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