how to get actual data type for Var in C# -
for below code, "gettype()" same (string) var result & result1.
var result = "abc"; var result1 = "10.17"; string = result.gettype().name; string b = result1.gettype().name;
how actual data type above variables?
by "actual data type" you, probably, mean "can data treated (converted) double, int" etc. if it's 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 treated int - intvalue } else if (double.tryparse(result, numberstyles.any, cultureinfo.invariantculture, out var doublevalue)) { // result1 can treated double - doublevalue } else { // result1 string can't converted int, double }
Comments
Post a Comment