【问题标题】:How to set an ints Hex Literal from a string,如何从字符串中设置整数十六进制文字,
【发布时间】:2010-10-25 08:00:40
【问题描述】:

我试图从 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.

【问题讨论】:

    标签: c# .net xml hex


    【解决方案1】:

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

    Int32 value = Convert.ToInt32(hexString, 16);
    

    【讨论】:

      猜你喜欢
      • 2014-03-10
      • 2011-06-18
      • 2017-08-07
      • 1970-01-01
      • 2013-04-28
      • 2017-08-12
      • 1970-01-01
      • 2019-07-27
      • 2013-09-06
      相关资源
      最近更新 更多