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

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

thorough guide for profiling racket code -