5. September 2013 18:46
/
Bala Vanchi
/
How to
/
Comments (0)
By default, .NET have the features of identifying the data type inside a string. Everybody using this feature already in our day-to-day development activity. i.e. none other than TryParse. This TryParse method will help us in identifying the right type from the string.
With the TryParse keyword of each data type I have created a method to return the type of the passing parameter. You can add other type or custom object types to this method which I explained it here.
private string GetType(string types)
{
string returnType = "object";
decimal de;
int i;
double d;
long l;
bool b;
if (int.TryParse(types, out i))
{
returnType = "int";
}
else if (long.TryParse(types, out l))
{
returnType = "long";
}
else if (double.TryParse(types, out d))
{
returnType = "double";
}
else if (decimal.TryParse(types, out de))
{
returnType = "decimal";
}
if (bool.TryParse(types, out b))
{
returnType = "bool";
}
return returnType;
}
0dda9ff6-c23c-4f28-a4a4-481e7db17a8e|0|.0|27604f05-86ad-47ef-9e05-950bb762570c