What is the equivalent of C#'s `default` in VB.NET?

前端 未结 3 1942
粉色の甜心
粉色の甜心 2021-01-01 16:53

I\'m normally at home in C#, and I\'m looking at a performance issue in some VB.NET code -- I want to be able to compare something to the default value for a type (kind of l

3条回答
  •  执笔经年
    2021-01-01 17:15

    The problem in your code is the IsNot operator, not the Nothing keyword. From the docs:

    The IsNot operator determines if two object references refer to different objects. However, it does not perform value comparisons.

    You're trying to do a value comparison with a reference operator. Once you realize this, either Jon Skeet's or Hans Passant's answers become obvious solutions.

提交回复
热议问题