0

Possible Duplicate:
Why isn't String.Empty a constant?

...and not const?

I know its probably a useless question, but I'm sort of curious on the reasoning behind this one. An empty string is an empty string so I do not foresee many chances of string.Empty being anything else than "". So why make it readonly?

Is there any other benefit I'm missing in not making it const?

Community
  • 1
  • 1
InBetween
  • 32,319
  • 3
  • 50
  • 90
  • 1
    Values marked `static` are still open to being modified, no? The intent with `readonly` is clear: no modification possible. – Bernard Aug 16 '11 at 18:48
  • Technically it isn't... http://thedailywtf.com/Comments/The-Disgruntled-Bomb.aspx?pg=2 Has a very nasty piece of code for disgruntled employees to leave lying around – RichK Aug 16 '11 at 18:51
  • woops yeah sorry, I meant const. Anyhow sorry for the duplicate, I should have checked before. – InBetween Aug 16 '11 at 18:52

2 Answers2

3

It IS static.

public static readonly string Empty;
Tejs
  • 40,736
  • 10
  • 68
  • 86
0

Readonly prevents it from being changed. Perhaps you mean "why isn't it a const"?

Mark Sowul
  • 10,244
  • 1
  • 45
  • 51