Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <blockquote> <p>Why is the default value of the string type null instead of an empty string?</p> </blockquote> <p>Because <code>string</code> is a <strong>reference type</strong> and the default value for all reference types is <code>null</code>. </p> <blockquote> <p>It's quite annoying to test all my strings for null before I can safely apply methods like ToUpper(), StartWith() etc...</p> </blockquote> <p>That is consistent with the behaviour of reference types. Before invoking their instance members, one should put a check in place for a null reference.</p> <blockquote> <p>If the default value of string were the empty string, I would not have to test, and I would feel it to be more consistent with the other value types like int or double for example.</p> </blockquote> <p>Assigning the default value to a specific reference type other than <code>null</code> would make it <strong>inconsistent</strong>.</p> <blockquote> <p>Additionally <code>Nullable&lt;String&gt;</code> would make sense.</p> </blockquote> <p><a href="http://msdn.microsoft.com/en-us/library/1t3y8s4s%28v=vs.110%29.aspx" rel="noreferrer"><code>Nullable&lt;T&gt;</code></a> works with the value types. Of note is the fact that <code>Nullable</code> was not introduced on the original <a href="http://msdn.microsoft.com/en-us/library/b3h38hb0(v=vs.80).aspx" rel="noreferrer">.NET platform</a> so there would have been a lot of broken code had they changed that rule.(<em>Courtesy <a href="https://stackoverflow.com/users/109749/jcolebrand">@jcolebrand</a>)</em></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload