IsNothing 与 Is Nothing [英] IsNothing versus Is Nothing

查看:28
本文介绍了IsNothing 与 Is Nothing的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这里是否有人使用 VB.NET 并且强烈偏好或反对使用 IsNothing 而不是 Is Nothing(例如,If IsNothing(anObject))If anObject Is Nothing...)?如果是,为什么?

Does anyone here use VB.NET and have a strong preference for or against using IsNothing as opposed to Is Nothing (for example, If IsNothing(anObject) or If anObject Is Nothing...)? If so, why?

如果您认为它们都同样可以接受,您认为最好选择一个并坚持使用,还是可以混合使用?

If you think they're both equally acceptable, do you think it's best to pick one and stick with it, or is it OK to mix them?

推荐答案

如果您查看正在执行的 MSIL,您会发现它不会编译为完全相同的代码.当您使用 IsNothing() 时,它实际上会调用该方法,而不仅仅是评估表达式.

If you take a look at the MSIL as it's being executed you'll see that it doesn't compile down to the exact same code. When you use IsNothing() it actually makes a call to that method as opposed to just evaluating the expression.

我倾向于使用Is Nothing"的原因是当我否定它时会变成IsNot Nothing"而不是Not IsNothing(object)",我个人认为这看起来更具可读性.

The reason I would tend to lean towards using "Is Nothing" is when I'm negating it becomes "IsNot Nothing' rather than "Not IsNothing(object)" which I personally feel looks more readable.

这篇关于IsNothing 与 Is Nothing的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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