Showing posts with label TryParse in C#. Show all posts
Showing posts with label TryParse in C#. Show all posts

Thursday, May 9, 2013

TryParse() in C#

in c#,we often convert data from one type to another.
Sometimes conversions may fail,to manage we will put conversion code block in try catch.
we can get rid off this by using TryParse().

Advantage:
No need to handle exception handling in conversions.

see below example


int quantity=0;
if (int.TryParse(txtQuantity.Text, out quantity) == false)
{
 quantity = 0;
}