<p>When 'val' below is not a <code>bool</code> I get an exception, I believe I can use <code>TryParse</code> but I'm not sure how best to use it with my code below. Can anyone help?</p>

<pre><code>checkBox.Checked = Convert.ToBoolean(val);
</code></pre>

<p>Thanks</p>

The code is as follows to determine whether the string
```
val
```
is a valid Boolean value and use it to set the
```
Checked
```
property if so. You need to decide what action you would take if it does not represent a valid value.
```
```
bool result;
if (bool.TryParse(val, out result))
{
    // val does represent a Boolean
    checkBox.Checked = result;
}
else
{
    // val does not represent a Boolean
}
```
```