任何引用/ MSDN教程以示支持,无论是"(!条件)如果"或QUOT;如果(条件==假)QUOT ;? [英] Any references / MSDN tutorials to show support for either "if (!condition)" or "if (condition == false)"?

查看:172
本文介绍了任何引用/ MSDN教程以示支持,无论是"(!条件)如果"或QUOT;如果(条件==假)QUOT ;?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于那些谁误读了一个问题:我们假设我们是在维基百科结果
我不是在寻找正确的方式,我找核实的引用来支持任何一方。



(请读到结尾)



上下文



在一个在不同的线程发表评论,一个人说的他的朋友们会恳求与我不同的观点的是否

 如果(!条件)

 如果(条件==假)





虽然我确信我知道如何做正确的事情™,我无法找到任何证据我的看法是既不C#代码,也没有设计准则正式。



问题



这有什么的大幅支持任何一方的展现除了常识?



(一段落广泛推崇的书或任何文件是在托管 microsoft.com 使用或对另一规定无论是风格回答


解决方案

如果(!条件)如果(条件)优于如果(条件==假)如果(条件==真)因为前者仅仅是为可读和更简洁的

底部区域http://se.inf.ethz.ch/old/teaching/ss2007/251-0290-00 /project/CSharpCodingStandards.pdf相对=nofollow> C#编码为.NET标准通过创建兰斯亨特说




避免对评估真或假的布尔条件




  //错误! 
如果(的isValid ==真)
{...}
//好!
如果(的isValid)
{...}



但它不是以任何方式官方,并没有来自微软。


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)

解决方案

if (!condition) and if (condition) are preferred over if (condition == false) and if (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:

Avoid evaluating Boolean conditions against true or false.

// Bad! 
if (isValid == true) 
{ ... } 
// Good! 
if (isValid) 
{ ... }

However it is not by any means official and it doesn't come from Microsoft.

这篇关于任何引用/ MSDN教程以示支持,无论是"(!条件)如果"或QUOT;如果(条件==假)QUOT ;?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆