I am trying to learn java from a C# background! I have found some nuances during my journey like C# doesn’t have an Integer as reference type it only has int as a primitive type; this lead me to a doubt if this translation would be correct!
String line ="Numeric string";//Java
string line = "Numeric string";//C#
int size;
size = Integer.valueOf(line, 16).intValue(); //In Java
size = int.Parse(line,System.Globalization.NumberStyles.Integer);//In C#
No, that’s not quite a valid translation – because the 16 in the Java code means it should be parsed as an integer. The Java code is closer to:
That overload of
Convert.ToInt32allows you to specify the base.Alternatively you could use:
I’m not keen on the name “allow hex specifier” as it suggests that a prefix of “0x” will be accepted… but in reality it means it’s always interpreted as hex.