How can I override TryParse?

Posted by cyclotis04 on Stack Overflow See other posts from Stack Overflow or by cyclotis04
Published on 2010-06-11T14:38:18Z Indexed on 2010/06/11 14:42 UTC
Read the original article Hit count: 318

Filed under:
|
|

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);
    }
}

© Stack Overflow or respective owner

Related posts about c#

Related posts about types