I got a weird error message when I tried to convert an object to bool, here is my code:
public partial class ModifierAuteur : DevExpress.XtraEditors.XtraForm
{
public ModifierAuteur(object getKeyDecesCheckBox)
{
decesCheckBox.Checked = getKeyDecesCheckBox == null ? null : (bool)getKeyDecesCheckBox;
}
}
and this is the error message :
Type of conditional expression cannot be determined because there is
no implicit conversion between<null>andbool
Assuming that the assignment is possible, you need to convert to a nullable
bool, like this:The inner cast to
boolunboxes the value, and the outer cast tobool?makes it compatible withnullof the conditional expression.If the left-hand side of the assignment does not allow
nulls, you need to decide on the value to set whengetKeyDecesCheckBoxisnull. Usually, that’s afalse: