By "actual data type" you, probably, mean "can the data be treated (converted) as double, int" etc. If it's your case, try using TryParse
, possible C# 7.0 (out var
construction) implementation:
var result1 = "10.17";
if (int.TryParse(result, out var intValue)) {
// result1 can be treated as int - intValue
}
else if (double.TryParse(result,
NumberStyles.Any,
CultureInfo.InvariantCulture,
out var doubleValue)) {
// result1 can be treated as double - doubleValue
}
else {
// result1 is a string which can't be converted to int, double
}