基本类型int double bool
扩展类型 Int32 Int64
switch(value.GetType().ToString())
{
case "System.String":
return Int32.Parse((string)value);
case "System.Int64":
return Int32.Parse(((long)value).ToString());
case "System.Int32":
return (int)value;
case "System.Double":
return (int)System.Math.Round((double)value, 0);
case "System.Boolean":
return 0;
case "System.DateTime":
return 0;
case "System.IO.MemoryStream":
return MyConvert.getInt(MyConvert.getString(value));
case "System.Byte[]":
return MyConvert.getInt(MyConvert.getString(value));
default:
return 0;
}
注意区分如果是System.String或者是System.Int64则要使用Int32.Parse();如果是System.Int32则直接用(int)强制类型转换。如果是double则需要调用System.Math.Round((double)value,0);