Why can you assign Nothing to an Integer in VB.NET?

后端 未结 5 1021
星月不相逢
星月不相逢 2021-01-17 07:22

Why am I allowed to assign Nothing to a value-type in VB.NET:

Dim x as Integer = Nothing

But I\'m not allowed to assign

5条回答
  •  我在风中等你
    2021-01-17 08:01

    Here's an interesting article about VB.NET and Nothing vs. Null. A small excerpt:


    ...value types, can’t be compared to Nothing or Null. Value types are types such as Integers and Bytes. From the Visual Basic Language Reference:

    A value type cannot hold a value of Nothing and reverts to its default value if you assign Nothing to it. If you supply a value type in Expression, IsNothing always returns False.

提交回复
热议问题