c# - ToString on null string -
why second 1 of these produce exception while first 1 doesn't?
string s = null; messagebox.show(s); messagebox.show(s.tostring()); updated - exception can understand, puzzling bit (to me) why first part doesn't show exception. isn't messagebox, illustrated below.
eg :
string s = null, msg; msg = "message " + s; //no error msg = "message " + s.tostring(); //error the first part appears implicitly converting null blank string.
because cannot call instance method tostring() on  null reference. 
and messagebox.show() implemented ignore null , print out empty message box.
Comments
Post a Comment