(this line refers to the question that has been merged). You should never use (int)someString
- this will never work (and the compiler will not let you).
However, int int.Parse(string)
and bool int.TryParse(string, out int)
(and their various overloads) are fair play.
Personally, I mostly use Convert
when dealing with reflection, so for me the choice is Parse
and TryParse
. First, when I expect a value as a real integer and want it to throw an exception differently. Secondly, when I want to check if it is a valid integer, I can decide what to do when it is / not.
Marc Gravell Feb 27 '11 at 9:17 2011-02-27 09:17
source share