Generic TryParse

Posted by Piers Myers on Stack Overflow See other posts from Stack Overflow or by Piers Myers
Published on 2010-06-02T21:16:30Z Indexed on 2010/06/02 21:24 UTC
Read the original article Hit count: 258

Filed under:
|
|

I am trying to create a generic extension that uses 'TryParse' to check if a string is a given type:

public static bool Is<T>(this string input)
{
    T notUsed;
    return T.TryParse(input, out notUsed);
}

this won't compile as it cannot resolve symbol 'TryParse'

As I understand, 'TryParse' is not part of any interface.

Is this possible to do at all?

© Stack Overflow or respective owner

Related posts about c#

Related posts about generic