intID1 = Int32.Parse(myValue.ToString());
intID2 = Convert.ToInt32(myValue);
Which one is better and why?
Well, Reflector says...
public static int ToInt32(string value)
{
if (value == null)
{
return 0;
}
return int.Parse(value, CultureInfo.CurrentCulture);
}
public static int Parse(string s)
{
return Number.ParseInt32(s, NumberStyles.Integer, NumberFormatInfo.CurrentInfo);
}
So they're basically the same except that Convert.ToInt32()
does an added null check.