In this case you can use the typeof
to enumerate through a list of types and determine what type it is.
https://msdn.microsoft.com/en-us/library/58918ffs.aspx
For example you can do something like that:
if (obj1.GetType() == typeof(int)){
// do something with int
}else if (obj1.GetType() == typeof(string)){
// do something with string
}
Otherwise if it isn't an object but just a value you can compare with is
:
if (myValue is Foo)
Foo foo = (Foo)myValue;
EDIT:
Ok I did a mistake. You have to use tryParse
to achieve what you want. The approach is pretty the same, you have to loop through different types and check the return value if the parsing was successful. For example:
int number;
bool result = Int32.TryParse(myString, out number);
if (result)
{
Console.WriteLine("Converted '{0}' to {1}.", myString, number);
}