Parsing/Converting String as INT using C#
In this blog, we are going to parse the string to specific INT data Type.
Usage:
int a =
TryParseInt("234", int.MinValue);//TRUE
int b =
TryParseInt("2B4", int.MinValue);//False
Response.Write(string.Format("A:{0},B:{1}", a, b)+"<br/>");
OUTPUT:
A:234,B:-2147483648
Method1: int.TryParse
Best to use if
there is uncertain about the input string.
|
Method 2: int.Parse
If you sure about the input string going to be valid, then go for this
method.
|
Thanks for reading this article. Have a nice day.

Lajapathy ArunPosted May 5, 2012, 5:35 AM
Now formatted with the code available in HTMl Editor.
Mahesh ChandPosted May 4, 2012, 10:14 PM
Hi Arun, please fix the spacing and formatting in the editor. The way I do is, copy from Word doc to Notepad and then copy from Notepad to the Blogs editor. Then format what I need. It will also cleanup your HTML :) Cheers!