If I declare a string but do not assign a value, the Equals
function throws an exception but it doesn't throw an exception if it is compared to a value.
The error list warns about the problem:
Warning BC42104 Variable
a
is used before it has been assigned a value. A null reference exception could result at runtime.
Dim a As String
Dim b as string = "bar"
a.Equals("foo") 'causes System.NullReferenceException
a = "foo" 'No exception although a is nothing
a = b 'No exception although a is nothing
I know the warning says it COULD cause an exception, but does anyone know why this is the happening?