Is the 'Is' VB.NET keyword the same as Object.ReferenceEquals?

纵然是瞬间 提交于 2019-12-01 00:19:44

问题


Is the Is VB.NET keyword the same as Object.ReferenceEquals?


回答1:


Yes, it is, unless combined with a TypeOf check.

Quote from MSDN:

The Is operator determines if two object references refer to the same object. However, it does not perform value comparisons. If object1 and object2 both refer to the exact same object instance, result is True; if they do not, result is False.

Is can also be used with the TypeOf keyword to make a TypeOf...Is expression, which tests whether an object variable is compatible with a data type.

BTW, also note the IsNot operator (which gives the boolean inverse of the matching Is expression):

IsNot is the opposite of the Is operator. The advantage of IsNot is that you can avoid awkward syntax with Not and Is, which can be difficult to read.



来源:https://stackoverflow.com/questions/2626206/is-the-is-vb-net-keyword-the-same-as-object-referenceequals

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!