I would like to override bool‘s TryParse method to accept “yes” and “no.” I know the method I want to use (below) but I don’t know how to override bool‘s method.
... bool TryParse(string value, out bool result)
{
if (value == "yes")
{
result = true;
return true;
}
else if (value == "no")
{
result = false;
return true;
}
else
{
return bool.TryParse(value, result);
}
}
You can’t override a static method. You could however create an extension method.
Put this in a static class, and call your code like this: