<p>I am working on a tool where I need to convert string values to their proper object types. E.g. convert a string like <code>"2008-11-20T16:33:21Z"</code> to a <code>DateTime</code> value. Numeric values like <code>"42"</code> and <code>"42.42"</code> must be converted to an <code>Int32</code> value and a <code>Double</code> value respectively. </p>

<p>What is the best and most efficient approach to detect if a string is an integer or a number? Are <code>Int32.TryParse</code> or <code>Double.TryParse</code> the way to go? </p>

In terms of efficiency, yes, TryParse is generally the preferred route.
If you can know (for example, by reflection) the target type in advance - but don't want to have to use a big
```
switch
```
block, you might be interested in using
```
TypeConverter
```
- for example:
```
```
DateTime foo = new DateTime(2008, 11, 20);
        TypeConverter converter = TypeDescriptor.GetConverter(foo);
        string s = converter.ConvertToInvariantString(foo);
        object val = converter.ConvertFromInvariantString(s);
```
```