将uint写为Hex而不是Int

时间:2015-11-02 10:36:00

标签: c# hex

在c#中,我将错误代码定义为

public const uint SOME_ERROR= 0x80000009;

我想将0x80000009写入文本文件,现在我正在尝试

 private static uint ErrorCode;
 ErrorCode = SomeMethod();
 string message = "Error: {0}.";
 message = string.Format(message, ErrorCode);

但是把它写成一个像“2147483656”这样的int,怎么能把它写成文本文件的十六进制呢?

2 个答案:

答案 0 :(得分:4)

您需要使用UInt32.ToString("X")输出uint为十六进制。

所以在你的情况下:

String.Format(message, ErrorCode.ToString("X"));

答案 1 :(得分:3)

你没有必要施展它。只需做

public ActionResult Pdf(string name, string description) {
    var product = new Product();
    product.Name = name;
    product.Description = description;

    var pdfResult = new PdfResult(product, "Pdf");

    return pdfResult;
}

如果您的方法location.href = @Url.Action("Pdf", "Controllername") + "?name=" + name + "&description=" + description; 返回message = string.Format(message, ErrorCode); ,那么您可以将int转换为Hex,如下所示:

SomeMethod()
相关问题