c# - 如何从字符串设置 ints 十六进制文字,

标签 c# .net 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.

最佳答案

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

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

关于c# - 如何从字符串设置 ints 十六进制文字,,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/848869/

相关文章:

c# - 测试 ASP.NET Core IMemoryCache 的正确方法

c# - 如何为解决方案中的每个项目创建单独的 nuget 包,并将项目引用转换为 nuget 依赖项?

c# - C# 中是否有 System.IO.BufferedStream 的替代方案?

php - 使用 SimpleXML 读取 RSS 提要

javascript - 单击按钮时如何调用此函数? (Javascript、XSLT、XML、HTML)

c# - 将 PouchDB 与 SQL Server 和 CouchDB 结合使用

c# - 在代码中将 X509 证书添加到商店

c# - 错误 : "The node to be inserted is from a different document context"

c# - 如何在 .NET 中自动换行注释?

python - SOAPpy 的复杂类型问题