All Convert.ToX functions that take an argument of type string ultimately access the Parse method of the corresponding data type.
For example, Convert.ToInt32(string) looks something like this:
public static int ToInt32(string value) { if (value == null) { return 0; } return int.Parse(value, CultureInfo.CurrentCulture); }
The same goes for all other digital conversion methods, including Decimal and DateTime . So it doesnβt matter which one you use; the result (and speed) will be the same anyway.
Indeed, the only difference is the if (value == null) guard clause at the beginning. Regardless of whether it is convenient, it depends on the specific use case. Generally, if you know that you have a non-zero string object, you can also use Parse . If you're not sure, ConvertToX is a safer bet requiring fewer zero checks.
source share