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

后端 未结 5 978
星月不相逢
星月不相逢 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 07:43

    When you assign Nothing to a value type in VB.Net it instantiates that type with its default value. So in this case you're not creating a null integer, but an integer that holds the default value of 0

提交回复
热议问题