I am trying to convert my nullable bool value and I am getting this error.
Cannot implicitly convert type 'bool?' to 'bool'. An explicit conversion exists (are you missing a cast?)
For example:
public virtual bool? MyBool
{
get;
set;
}
if (!MyBool){}
As the error states, you can’t use a
bool?in a conditional. (What would happen if it’snull?)Instead, you can write
if (MyBool != true)orif (MyBool == false), depending on whether you want to includenull. (and you should add a comment explaining that)