Why use !! when converting int to bool?

前端 未结 10 1836
梦谈多话
梦谈多话 2020-11-30 22:37

What can be a reason for converting an integer to a boolean in this way?

bool booleanValue = !!integerValue;

instead of just



        
10条回答
  •  我在风中等你
    2020-11-30 22:52

    Because !integerValue means integerValue == 0 and !!integerValue thus means integerValue != 0, a valid expression returning a bool. The latter is a cast with information loss.

提交回复
热议问题