IsNothing versus Is Nothing

2020-01-27 13:47发布

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?

EDIT: 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?

9条回答
趁早两清
2楼-- · 2020-01-27 14:50

I also tend to use the Is Nothing version partially from using it as much as I do in SQL.

查看更多
时光不老,我们不散
3楼-- · 2020-01-27 14:50

Is Nothing requires an object that has been assigned to the value Nothing. IsNothing() can take any variable that has not been initialized, including of numeric type. This is useful for example when testing if an optional parameter has been passed.

查看更多
神经病院院长
4楼-- · 2020-01-27 14:51

I initially used IsNothing but I've been moving towards using Is Nothing in newer projects, mainly for readability. The only time I stick with IsNothing is if I'm maintaining code where that's used throughout and I want to stay consistent.

查看更多
登录 后发表回答