VB.NET: Empty string vs. Null Reference

0.00 avg. rating (0% score) - 0 votes

‘If st is an empty string, e.g.:
Dim st as String = String.Empty

‘The following returns TRUE:
Dim ok as Boolean = (st = Nothing)

‘But this returns FALSE:
Dim ok as Boolean = (st is Nothing)

The “=” operator for String data type in VB.NET treats empty strings and null strings equally whereas the “is” operator treats strings as reference and does not care about the values. An empty string is not a null reference.

0.00 avg. rating (0% score) - 0 votes


A tough developer who likes to work on just about anything, from software development to electronics, and share his knowledge with the rest of the world.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>