I have an object AlternateName.IsMaidenName
I want to cast that to a checkbox - IsMaidenName
It wont let me cast that as it says Cannot convert source type nullable to target type bool.
I've had this issue in other spots within our application but I wanted to throw it out there for a better way to handle these issues.
IsMaidenNameChecked = AlternateName.IsMaidenName;
It is quite logical that you cannot cast a nullable bool to a bool, since, what value should the bool have, when the nullable contains null ?
What I would do, is this:
IsMaidenNameChecked = AlternateName.IsMaidenName ?? false;
IsMaidenName.Checked = AlternateName.IsMaidenName.GetValueOrDefault();
See: http://msdn.microsoft.com/en-us/library/72cec0e0.aspx
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With