Converting string to number in c#

3

I am using the below code int.Parse("376") the result is coming as

int.Parse("376") = 0x00000178 int

and i tried to do as

Convert.Toint32("376") also then the result is same

please help me how to convert string to number?

c#-4.0
asked on Stack Overflow Oct 20, 2013 by Arya

3 Answers

3

It is working fine. 0x00000178 is the hexadecimal representation of 376.

Your Hex button is enabled in Visual Studio.

enter image description here

answered on Stack Overflow Oct 20, 2013 by Rahul Tripathi • edited Oct 20, 2013 by Rahul Tripathi
1

0x00000178 is the hexadecimal representation for 376, so using int.Parse or Convert.ToInt32 is OK.

However, I suggest to use the int.TryParse() method:

int i;
if (int.TryParse(yourString, out i))
{
    // the string is converted successfully to an int, now you can find the int value in the variable 'i'
}
else
{
   // Can't convert to an int: the string contains probably some characters that aren't digits
}
answered on Stack Overflow Oct 20, 2013 by ProgramFOX • edited Oct 20, 2013 by ProgramFOX
0

It is working fine. 0x178 is hex based for 376 in decimal.

answered on Stack Overflow Oct 20, 2013 by Hogan

User contributions licensed under CC BY-SA 3.0