如何从字符串中设置整数Hex Literal,

Fus*_*awn 2 .net c# xml hex

我试图从xml设置文件加载一个十六进制文字,我可以很好地解析xml并从文件中获取所需的字符串,

但我似乎无法设置一个int变量值:/

码:

    int PlayerBaseAddress = System.Convert.ToInt32(ConfigLoader.GetSetting("PlayerBaseAddress"));
    // Input string was not in a correct format.

    public static string GetSetting(string Val)
    {
       // This loads from the xml file, Pretend its hardcoded to return a string of 0x17EAAF00
    }

    int PlayerBaseAddress = 0x17EAAF00; // This works.
Run Code Online (Sandbox Code Playgroud)

Dan*_*ner 7

您必须为重载方法提供字符串的基础Convert.ToInt32(String value, Int32 fromBase).

Int32 value = Convert.ToInt32(hexString, 16);
Run Code Online (Sandbox Code Playgroud)