【发布时间】:2010-05-10 09:15:58
【问题描述】:
由于某种原因,以下 C# 控制台程序总是输出:
32
假的
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);
}
}
}
【问题讨论】:
-
IIRC,Java 有同样的愚蠢。
-
尽管有它的名字,
AllowHexSpecifier不允许任何十六进制说明符。它只是将事物解释为十六进制。 :-/