任何显示对“if (!condition)”或“if (!condition)”支持的参考资料/MSDN 教程或者“if(条件==假)”?
对于那些误读问题的人:让我们假装我们在维基百科。< /strong>
我不是在寻找“正确的方式”,我正在寻找可验证的参考资料来支持任何一方。
(请读到最后)
上下文
在不同线程的评论中,一个人说他的朋友们可能会不同意我对 C# 是否
if (!condition)
更
if (condition == false)
喜欢 的看法。
尽管我确信我知道如何做正确的事™,但我无法找到任何证据证明我的观点在 C# 编码和设计指南中都不是正式的。
问题:
除了常识之外,还有什么实质性可以表明支持任何一方吗?
(一本广受好评的书中的段落或任何托管在 microsoft.com
的文档,使用或规定了任一风格另一个将回答问题)
For those who misread the question: let's pretend we're on Wikipedia.
I'm not looking for “the right way”, I'm looking for verifiable references to support either side.
(Please read to the end)
The Context
In a comment on a different thread, a person said his friends would beg to differ with my opinion on whether
if (!condition)
or
if (condition == false)
is preferred in C#.
As much as I was sure I know how to do the Right Thing™, I was unable to find any evidence my opinion is official in neither C# coding nor design guidelines.
The Question
Is there anything substantial to show in support of either side, apart from the common sense?
(a paragraph in a widely admired book or any document hosted at microsoft.com
that uses or prescribes either style over another will answer the question)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
if (!condition)
和if (condition)
优于if (condition == false)
和if (condition == true)
因为前者同样可读且不那么冗长。C# 编码标准第 13 页的底部部分for .NET 由 Lance 创建亨特 说:
然而,它绝不是官方的,也不是来自微软。
if (!condition)
andif (condition)
are preferred overif (condition == false)
andif (condition == true)
because the former is just as readable and less verbose.Bottom section of page 13 of C# Coding Standards for .NET created by Lance Hunt says:
However it is not by any means official and it doesn't come from Microsoft.
有时,如果条件为假是一种极端的边缘情况,我会使用 if (condition == false) - 它让我注意到了这一事实。
Sometimes I use if (condition == false) if the condition being false is an extreme edge case - it brings attention to that fact for me.