I am trying to read in a hex value from a text box and then put it in a uint, this is the code:
UInt32 x = Convert.ToUInt32(location_txtbox.ToString());
Why, I want to pass x to some unmanaged code and the function header requires a DWORD.
I'm getting an 'input string was not in correct format error? I am trying to input values such as 0x7c or 0x777 but I keep getting errors?
Thanks.
Use this overload of Convert.ToUInt32 where you specify the base of the conversion. It should work with or without the leading "0x".
UInt32 x = Convert.ToUInt32(location_txtbox.Text, 16);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With