Local variables or direct statements?

前端 未结 7 1600
旧时难觅i
旧时难觅i 2021-01-25 23:55

I am currently studying C# and I really want to get a good coding style from the beginning, so I would like to hear opinions from you professionals on this matter.

Shoul

7条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-01-26 00:40

    You should use the more verbose style if putting it all in one line would make it too long or complicated.

    You should also use a separate variable if the variable's name would make it easier to understand the code:

    bool mustWait = someCommand.ConflictsWith(otherCommand);
    if (mustWait) {
        ...
    }
    

    In such cases, you should consider using an enum for additional readability.

提交回复
热议问题