if-statement

Conditional operator without return value

故事扮演 提交于 2020-11-29 03:36:50
问题 I have this code: bool value = false; if(value) { Console.Write("true"); } else { Console.Write("false"); } and I want to shorten it by using the conditional operator but I can't find the correct syntax. bool value = false; value ? Console.Write("true") : Console.Write("false"); // does not work 回答1: Put the operator inside Console.Write Console.Write(value ? "true" : "false"); or if you really want to write the value: Console.Write(value); if you want to call 2 different Methods, you can

Using OR operator in a jquery if statement

生来就可爱ヽ(ⅴ<●) 提交于 2020-11-27 01:42:47
问题 I need to use the OR operator in a jQuery if statement to filter out 10 states. My code works wile only excluding one state, but fails when i try to include multiple states. Is there a correct way to do this? Code I am am using : if ((state != 10) || (state != 15) || (state != 19) || (state != 22) || (state != 33) || (state != 39) || (state != 47) || (state != 48) || (state != 49) || (state != 51)) return true; Thanks 回答1: Think about what if ((state != 10) || (state != 15) || (state != 19) |

Using OR operator in a jquery if statement

牧云@^-^@ 提交于 2020-11-27 01:42:12
问题 I need to use the OR operator in a jQuery if statement to filter out 10 states. My code works wile only excluding one state, but fails when i try to include multiple states. Is there a correct way to do this? Code I am am using : if ((state != 10) || (state != 15) || (state != 19) || (state != 22) || (state != 33) || (state != 39) || (state != 47) || (state != 48) || (state != 49) || (state != 51)) return true; Thanks 回答1: Think about what if ((state != 10) || (state != 15) || (state != 19) |