getting message condition is always true

让人想犯罪 __ 提交于 2019-12-13 08:24:25

问题


I'm getting message from resharper as condition is always true for following code

if (filters == "answers" || "solution") {

}

what's happening here in this code?


回答1:


if (filters == "answers" || "solution") {

}

In the above code "solution" is true always

So, Change to this

  if (filters == "answers" || filters =="solution") {

    }

Example

If("i")
{

}

Above is true always.

So, In your code the second condition returns TRUE always

As per the Boolean OR , [Anything with TRUE] is always TRUE

You have two predicates , So your truth table will be

   i/p               o/p
TRUE   FALSE        True
FALSE  TURE         True
FALSE  FALSE         False
TRUE   TRUE         True

in your code, You will never get the condition #1 and #3 so, It will be true always

so your code will be true always



来源:https://stackoverflow.com/questions/27498885/getting-message-condition-is-always-true

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!