|
How to convert String to Int in C#
( 'System.Convert.ToInt32()' vs. 'Int32.Parse()' )
We have two ways how to convert string to int. We can use 'System.Convert.ToInt32()'
Source code:
string
strMyString = "56";
int intMyInt = System.Convert.ToInt32(strMyString);
This will return zero value if 'strMyString = null'
The second way is to use 'Int32.Parse()'
Source code:
string
strMyString = "56";
int intMyInt = Int32.Parse(strMyString);
But this will throw exception if 'strMyString = null' !!!
Comments
Add your comment
|
List of articles
How to compare two Strings in C# Smart utilities |
Webdesign (c) 2009 - 2024 Supremus.sk |