将字符串转换为uint

fla*_*404 4 c# visual-studio-2008

我试图从文本框中读取十六进制值,然后将其放在uint中,这是代码:

UInt32 x = Convert.ToUInt32(location_txtbox.ToString());
Run Code Online (Sandbox Code Playgroud)

为什么,我想将x传递给一些非托管代码,函数头需要一个DWORD.

我收到的'输入字符串格式错误不正确?我试图输入0x7c或0x777等值,但我一直在收到错误?

谢谢.

Jef*_*ado 14

使用Convert.ToUInt32的这个重载,您可以在其中指定转换的基础.它应该使用或不使用前导"0x".

UInt32 x = Convert.ToUInt32(location_txtbox.Text, 16);
Run Code Online (Sandbox Code Playgroud)