I am trying to assign null
value to Boolean variable but it is not taking it
bool b = null;
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.