C# 中 bool 的默认值

csharpprogrammingserver side programming更新于 2025/11/25 12:48:00

使用 default 运算符获取 bool 类型的默认值 −

bool a = default(bool);

上面,我们使用了 default 关键字来获取默认值。

让我们看看显示 bool − 默认值的代码

示例

using System;

public class Demo {
   public static void Main() {
      bool a = default(bool);
      // bool 的默认值
      Console.WriteLine("bool 类型的默认值 = "+a);
   }
}

输出

以下是输出。它显示一个空格,即 False。

bool 类型的默认值 = False

相关文章