C#: When should I use TryParse?

Posted by zxcvbnm on Stack Overflow See other posts from Stack Overflow or by zxcvbnm
Published on 2010-03-15T19:48:37Z Indexed on 2010/03/15 19:49 UTC
Read the original article Hit count: 268

Filed under:
|
|

I understand it doesn't throw an Exception and because of that it might be sightly faster, but also, you're most likely using it to convert input to data you can use, so I don't think it's used so often to make that much of difference in terms of performance.

Anyway, the examples I saw are all along the lines of an if/else block with TryParse, the else returning an error message. And to me, that's basically the same thing as using a try/catch block with the catch returning an error message.

So, am I missing something? Is there a situation when this is actually useful?

© Stack Overflow or respective owner

Related posts about c#

Related posts about exception