vb.net - OPTION STRICT OFF - NULL Exception -


please see code below:

dim strhidereason string = strhidereason & " " & objdbdr.getname(inthidecheck) & " " & objdbdr(inthidecheck) 

objdbdr(inthidecheck) null. objdbdr datareader.

the code above compiles, trying set option strict on, have this:

dim strhidereason string = strhidereason & " " & objdbdr.getname(inthidecheck) & " " & cstr(objdbdr(inthidecheck)) 

it throws exception. can refactor code resolve this, confused why first compiles. compiler ignore objects null in string concatenations when option strict off?

when have option strict off:
on runtime object objdbdr(inthidecheck) automatically converted(if possible) type string.
msdn

for strings in visual basic, empty string equals nothing

objdbdr(inthidecheck) return nothing converted string empty string.

when have option strict on:
option restrict implicit conversions, , must convert objects string self.
function cstr if parameter null, runtime error throw

this answer explain why runtime error thrown:
https://stackoverflow.com/a/979911/1565525


Comments

Popular posts from this blog

google api - Incomplete response from Gmail API threads.list -

Installing Android SQLite Asset Helper -

Qt Creator - Searching files with Locator including folder -