如何在 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+ 瀏覽

啟動您的 事業

透過完成課程獲得認證

入門
廣告