What is the OR operator in an IF statement

前端 未结 11 853
轮回少年
轮回少年 2020-12-14 05:50

In C#, how do I specify OR:

if(this OR that) {do the other thing}

I couldn\'t find it in the help.

Update:

11条回答
  •  余生分开走
    2020-12-14 06:50

    The reason this is wrong:

    if (title == "User greeting" || "User name") {do stuff};
    

    is because what that's saying is

    If title equals the string "User greeting"

    or just "User name" (not if title equals the string "User name"). The part after your or would be like writing

    if ("User name")
    

    which c# doesn't know what to do with. It can't figure out how to get a boolean out of "User name"

提交回复
热议问题