Assign NULL value to Boolean variable

前端 未结 3 1177
既然无缘
既然无缘 2021-02-05 02:19

I am trying to assign null value to Boolean variable but it is not taking it

bool b = null;
3条回答
  •  悲&欢浪女
    2021-02-05 02:44

    C# has two different categories of types: value types and reference types. Amongst other, more important distinctions, value types, such as bool or int, cannot contain null values.

    You can, however, use nullable version of value types. bool? is a C# alias for the .NET Nullable type (in the same way string is an alias for String) and can contain null values.

提交回复
热议问题