UInt32.TryParse() hex-number not working

后端 未结 4 1407
滥情空心
滥情空心 2020-12-10 11:17

For some reason the following C# Console program always outputs:

32
False
wtf=0

What am I doing wrong?



        
4条回答
  •  佛祖请我去吃肉
    2020-12-10 12:09

    // stupid but effective way to improve the parsing
    char[] _trim_hex = new char[] {'0','x'};
    int temp;
    
    if (int.TryParse(value.TrimStart(_trim_hex), NumberStyles.HexNumber, null, out temp))
    {
        // temp is good
    }
    

提交回复
热议问题