Use metadata if you can
What you have to guess which data types is not a good idea.
Two things
1 Where do the data come from?
If this is a database, are you sure these are strings? If it is a database, some metadata should be returned that will tell you what the data types are.
If it is an Xml file, is there a specific schema that will give you types?
2 If you need to keep on guessing.
Remember that you can have strings that are numbers, but are perfectly valid strings, such as phone numbers, bank account numbers, which are best expressed as strings. In addition, these digits can have many digits, if you convert them to doubles, you may lose some digits for floating point inaccuracies (you must be in order up to 14 or 15 digits)
I am sure of this - because I did not have time to type this word - there are many answers telling you how to do this (i.e. tryparse int first, then double, then test length for char, if not string, etc. etc.), but if I were you, I would try NOT to do this and see if there is any way that you can get, or pass some metadata that will tell you what type it is, not just the type which may be
Binary binary
source share