Convert.ToBoolean fails with “0” value

后端 未结 8 2235
清歌不尽
清歌不尽 2020-12-14 16:37

I\'m trying to convert the value \"0\" ( System.String ) to its Boolean representation, like:

var myValue = Convert.To         


        
8条回答
  •  一生所求
    2020-12-14 17:29

    For a successful conversion to occur, the value parameter must equal either Boolean.TrueString, a constant whose value is True, Boolean.FalseString, a constant whose value is False, or it must be null. In comparing value with Boolean.TrueString and Boolean.FalseString, the method ignores case as well as leading and trailing white space.

    from MSDN

    because Convert.ToBoolean expects a true if value is not zero; otherwise, false. numerical value and True or False String value.

提交回复
热议问题