C# 中 bool 的預設值


使用預設運算子來獲取 bool 型別的預設值 −

bool a = default(bool);

在上面,我們使用了 default 關鍵字來獲取預設值。

讓我們看看顯示 bool 預設值程式碼 −

示例

 線上演示

using System;

public class Demo {
   public static void Main() {
      bool a = default(bool);
      // default for bool
      Console.WriteLine("Default for bool type = "+a);
   }
}

輸出

以下為輸出結果。它顯示了一個空格,即 False。

Default for bool type = False

更新於: 2020-06-22

2K+ 瀏覽量

助力你的 職業生涯

透過完成課程獲得認證

開始進行
廣告
© . All rights reserved.