我试图从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.
答案 0 :(得分:7)
您必须将字符串的基础提供给重载方法Convert.ToInt32(String value, Int32 fromBase)
。
Int32 value = Convert.ToInt32(hexString, 16);