public static int ToInt(this object source) { int val = 0; if (source != null) { string str = Convert.ToString(source); if (!string.IsNullOrEmpty(str)) { int.TryParse(str, out val); if (val <= 0) { try { val = (int)Convert.ToDouble(str); } catch (Exception) { } } } } return val; }
No comments:
Post a Comment