c# - What is better: int.TryParse or try { int.Parse() } catch -
i know.. know... performance not main concern here, curiosity, better?
bool parsed = int.tryparse(string, out num); if (parsed) ...
or
try { int.parse(string); } catch () { something... }
better highly subjective. instance, prefer int.tryparse
, since don't care why parsing fails, if fails. however, int.parse
can (according documentation) throw 3 different exceptions:
- the input null
- the input not in valid format
- the input contains number procudes overflow
if care why fails, int.parse
better choice.
as always, context king.
Comments
Post a Comment