35

string.Emptyが であり、 ではreadonlyない理由を理解しようとしていconstます。この投稿を見ましたが、マイクロソフトが書いたコメントがわかりません。Jon Skeetがコメントで書いたように、 「わかりません。正直言って、あまり意味がありません...」

共有ソース共通言語インフラストラクチャ 2.0 リリース。string.cs は sscli20\clr\src\bcl\system\string.cs にあります

// 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 = ""; 

ここには String コンストラクター呼び出しが表示されず、さらに、リテラルとしてマークされています - ""

誰かが平文で説明してくれませんか、コメントの意味と、なぜではstring.Empty readonlyないのconstですか?


更新:
Eric Lippertは、削除された回答にコメントしました:

私は昼食時に C# のベテランの 1 人にこのことについて尋ねました。

4

1 に答える 1