object转成int?值
2014-12-31 18:37:31 访问(1778) 赞(0) 踩(0)
/// <summary>
/// object转成int?值
/// </summary>
/// <param name="obj"></param>
/// <returns></returns>
public int? IntNullConvertTo(object obj)
{
if (obj is int)
return (int)obj;
if (obj == null)
return null;
string str = obj.ToString();
if (str.Length == 0)
return null;
int theResult = int.MinValue;
if (int.TryParse(str, out theResult))
return theResult;
throw new Exception
(
"方法:"
+ MethodBase.GetCurrentMethod().ReflectedType.FullName
+ " "
+ MethodBase.GetCurrentMethod().ToString()
+ " 发生异常:"
+ "obj == " + str + " 不是有效的整型值。"
);
}
标签:
object转成int?值 


上一条:
下一条:
相关评论
发表评论