Convert a string containing a hexadecimal value starting with “0x” to an integer or long

后端 未结 4 2020
庸人自扰
庸人自扰 2020-12-05 18:23

How can I convert a string value like "0x310530" to an integer value in C#?

I\'ve tried int.TryParse (and even int.TryParse with Syste

4条回答
  •  星月不相逢
    2020-12-05 18:27

    If you remove the leading 0x, you could use int.Parse

    int a = int.Parse("1310530", NumberStyles.AllowHexSpecifier);
    

提交回复
热议问题