I want to write a function that format int
and decimal
differently into string
I have this code:
and I want to rewrite it to generi
DoFormat(int value)
{
}
DoFormat(double value)
{
}
If you insist on using generics:
switch (value.GetType().Name)
{
case "Int32":
break;
case "Double":
break;
default:
break;
}
OR
if (value is int)
{
int iValue = (int)(object)value;
}
else if (value is double)
{
double dValue = (double)(object)value;
}
else
{
}