gpt4 book ai didi

c# - UInt32.TryParse() 十六进制数不工作

转载 作者:可可西里 更新时间:2023-11-01 08:02:31 24 4
gpt4 key购买 nike

出于某种原因,以下 C# 控制台程序总是输出:

32
False
wtf=0

我做错了什么?

using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Globalization;

namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine(Convert.ToUInt32("0x20", 16));
UInt32 wtf = 0;
Console.WriteLine(UInt32.TryParse("0x20",
NumberStyles.HexNumber, // I've tried also AllowHexSpecifier
CultureInfo.InvariantCulture, // I've also tried CurrentCulture
out wtf));
Console.WriteLine("wtf={0}", wtf);
}
}
}

最佳答案

您需要删除“0x”前缀。请看this blog entry

关于c# - UInt32.TryParse() 十六进制数不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2801509/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com