<分区>
就可读性而言,哪种样式更好?
bool isNew = (SelectList.Key > 0) ? true: false;
或
bool isNew = SelectList.Key > 0;
我知道这很琐碎,但只是想让它变得更好......谢谢
编辑:交换条件语句中的值
标签 c# c++ .net c coding-style
<分区>
就可读性而言,哪种样式更好?
bool isNew = (SelectList.Key > 0) ? true: false;
或
bool isNew = SelectList.Key > 0;
我知道这很琐碎,但只是想让它变得更好......谢谢
编辑:交换条件语句中的值
最佳答案
我会说这样更好
bool isNew = SelectList.Key > 0;
或者你可以提高可读性,在我看来,这样写
//set the value of isNew to true if bla bla else false.
bool isNew = (SelectList.Key > 0);
后者会迫使我首先处理表达式,而不是让我觉得您正在将 SelectList.Key
分配给 isNew
。
关于c# - 哪个更利于可读性?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19264050/