Why does the second of them throw an exception, and the first does not work?
string s = null; MessageBox.Show(s); MessageBox.Show(s.ToString());
Updated - an exception that I can understand, a cryptic bit (for me) is why the first part does not show an exception. This has nothing to do with Messagebox, as shown below.
For example:
string s = null, msg; msg = "Message is " + s; //no error msg = "Message is " + s.ToString(); //error
The first part is an implicit conversion of null to empty string.
string tostring null c # exception
MartW Jan 25 2018-11-11T00: 00Z
source share