Hi every body!
Could someone help me in converting a string to integer in C#?
Thanks.
Printable View
Hi every body!
Could someone help me in converting a string to integer in C#?
Thanks.
You can use the System.Convert class.
Like this:
int iNumber = System.Convert.ToInt32(myString);
Easy way of converting a string to an interger
int i = Int32.Parse(String);
Similarly converting a string to a long is done as
long d = Int64.Parse(String);
Similar to what armtusk replied, the following also works (just a matter of taste, I think using the same datatypes adds to more consistant code):
int i = int.Parse(String);
or
long d = long.Parse(String);
Of course, it also works with doubles and floats .