For instance, in the following scenario
Convert.Int64(string somstring)
or
long.Parse(string somstring);
appear to be doing same kind of work. Which one is a better practice ?
Thanks
If you look at the source, Convert.ToInt64(string) simply calls long.Parse, but checks that the string isn't null first.
I would recommend callings long.Parse because it makes the intent (string parsing) clearer.
I recommend using the Convert class if the type that you're converting from might change. (Or if you're converting from object)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With