Assign NULL value to Boolean variable

前端 未结 3 1178
既然无缘
既然无缘 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<bool> type (in the same way string is an alias for String) and can contain null values.

    0 讨论(0)
  • 2021-02-05 02:55

    You need to use a nullable bool:

    bool? b = null;
    
    0 讨论(0)
  • 2021-02-05 02:56

    For this you need to use following code to assign NULL value.

    Nullable<bool> b=null;
    
    0 讨论(0)
提交回复
热议问题