What does Nothing mean in VB.NET?

VB.NET Language Basic Fresher1–2 Yrs Conceptual 1 min read

Quick Answer

Nothing in VB.NET is both null (for reference types) and the default value (for value types). Dim i As Integer = Nothing sets i to 0, not null. You check with If x Is Nothing (reference equality), not =.

Nothing is overloaded in VB.NET. For a class it means a null reference, exactly like C#'s null. But for a value type like Integer, assigning Nothing gives you the default — zero — not null. And for a nullable value type it means the “has no value” state. The other thing is you check it with If x Is Nothing, using Is for reference comparison, rather than =, which does a value comparison and can give misleading results.

  • For a reference type, Nothing = a null reference, same as C#'s null.
  • For a value type, Nothing = the zero-initialised value (0, False, DateTime.MinValue).
  • For a nullable value type (Integer?), Nothing means the null (no value) state.
  • Comparison: Is Nothing / IsNot Nothing; using = Nothing compiles but does a value comparison that's often not what you want.