Multiple choice technology programming languages

How is the Nullable variable declaration done?

  1. Nullable<bool> b=null;

  2. bool b=null;

  3. <Nullable> bool b=null;

  4. bool b= <Nullable>;

Reveal answer Fill a bubble to check yourself
A Correct answer
Explanation

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.

AI explanation

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#.