How is the Nullable variable declaration done?
-
Nullable<bool> b=null;
-
bool b=null;
-
<Nullable> bool b=null;
-
bool b= <Nullable>;
The Nullable struct allows value types to be assigned null, which isn't possible for regular value types. Nullable can hold true, false, or null. Option A uses the correct generic Nullable syntax. Regular bool variables cannot be assigned null directly.
In C#, Nullable is the generic struct that wraps a value type to allow it to also hold null; 'Nullable b = null;' is valid, explicit syntax for declaring a nullable boolean (equivalent to the shorthand 'bool? b = null;'). Plain 'bool b = null;' doesn't compile because bool is a non-nullable value type. The other two options use invalid/nonsensical syntax (' bool b' and assigning a bare '' token) that isn't valid C#.