-
int.Parse
I'm trying to make the following lines to work:
int i = int.Parse("0xA");
Console.WriteLine(i);
i.e: i want parse to take the hex number, convert it to int and print it.
As I read in the manual, we can add another parameter to Parse - FormatProvider, that will do the task, but I can't understand how to use that FormatProvider.
Anyone has a solution?
-
Code:
int i = Int32.Parse("A", System.Globalization.NumberStyles.AllowHexSpecifier);
Martin
-
Great. It works perfect. Thanks
-
alternatively,
int a = Convert.ToInt32("0xA",16);
MessageBox.Show(a.ToString());
-Paresh
-
can I use Convert() to convert any base?
-
yes
2 , 8 16 etc.. octal, int, decimal 10 , hex 16 ...
Paresh
-
cool. nice to know that, thanks :)
-
specially
Convert
and
System.Text... classes are typically very important since they are the most needfull classes to change one data format to another data format.
-Thanx
Paresh