开发者

Int32.Parse() returns 0x0001 when 0 is expected - why?

开发者 https://www.devze.com 2023-02-01 07:33 出处:网络
I am using Int32.Parse() to convert the value of a DropDownList; however the returned value after conversion is:

I am using Int32.Parse() to convert the value of a DropDownList; however the returned value after conversion is:

0x0001

instead of the expected 0.

My code is:

myObject.Id = Int32.Parse(ddlName.Selected开发者_Go百科Value);

The selected value is "0" in this case. Why does it return a '0x0001' instead of a 0? What is happening and is that a memory register address?


Are you checking through debug Window ?

Check if you have enabled Viewing as Hex in Visual studio watch.


int.Parse(string s) uses the default CultureInfo, however I'm absolutely sure "0" can't be parsed to 0x0001 in any of the cultures(I looped all the cultures and see if "0" will be parsed to other values contains "0x"). So somewhere else is wrong. I think you'd better check:

(1) string s = ddlName.SelectedValue.ToString();  //make sure s is "0"
(2) int num = int.Parse(s);  //check if num is 0 or not
(3) myObject.Id = num;   //check the type of myObject.Id(supposed an int/long)
(4) Check the "set" method of myObject.Id (if there is one)
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号