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.