intID1 = Int32.Parse(myValue.ToString()); intID2 = Convert.ToInt32(myValue);
Which one is better and why?
They are exactly the same, except that Convert.ToInt32(null) returns 0.
Convert.ToInt32(null)
0
Convert.ToInt32 is defined as follows:
Convert.ToInt32
public static int ToInt32(String value) { if (value == null) return 0; return Int32.Parse(value, CultureInfo.CurrentCulture); }