Note that there are some explanatory texts on larger screens.

plurals
  1. POMeaning of confusing comment above "string.Empty" in .NET/BCL source?
    primarykey
    data
    text
    <p>I'm trying to understand why <code>string.Empty</code> is <code>readonly</code> and not a <code>const</code>. I saw <a href="https://stackoverflow.com/q/507923/601179">this</a> Post but I don't understand the comment Microsoft wrote about it. As Jon Skeet <a href="https://stackoverflow.com/a/8462706/601179">wrote</a> in a comment <em>"I don't know - it doesn't make much sense to me, to be honest..."</em></p> <p><a href="http://www.microsoft.com/downloads/details.aspx?FamilyId=8C09FD61-3F26-4555-AE17-3121B4F51D4D&amp;displaylang=en" rel="noreferrer">Shared Source Common Language Infrastructure 2.0 Release</a>. string.cs is in sscli20\clr\src\bcl\system\string.cs</p> <pre><code>// The Empty constant holds the empty string value. //We need to call the String constructor so that the compiler doesn't mark this as a literal. //Marking this as a literal would mean that it doesn't show up as a field which we can access //from native. public static readonly String Empty = ""; </code></pre> <p>I can't see here any String constructor call and furthermore, it's marked as literal - <strong>""</strong> </p> <p>Can someone please explain me in plain text, What does the comment mean and why is <code>string.Empty</code> <code>readonly</code> and not a <code>const</code>?</p> <hr> <p><strong>Update:</strong><br> <a href="https://stackoverflow.com/users/88656/eric-lippert">Eric Lippert</a> commented on by now a <a href="https://stackoverflow.com/a/8487944/601179">deleted answer</a>:</p> <blockquote> <p>I asked one of the C# old-timers over lunch about this and he did not recall specifically why this decision was made, but conjectured that it had something to do with interning.</p> </blockquote>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    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