z contains NULL. Why doesn't the output window show the NULL? Is it because NULL is not a value?
int? x = null;
int? y = 1;
int? z = 0;
z = x + y;
Debug.WriteLine(z);

When you look into the reference source of Console.WriteLine(Object), you can see that .NET calls System.IO.TextWriter.WriteLine(Object) which does explicitly check for null and will then output a blank line:
public virtual void WriteLine(Object value) {
if (value==null) {
WriteLine();
}
else {
// Call WriteLine(value.ToString), not Write(Object), WriteLine().
// This makes calls to WriteLine(Object) atomic.
IFormattable f = value as IFormattable;
if (f != null)
WriteLine(f.ToString(null, FormatProvider));
else
WriteLine(value.ToString());
}
}
Debug.WriteLine(Object) behaves the same way but is a bit more complicated. It eventually calls System.Diagnostics.TraceListener.WriteLine(Object).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With