0

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

To make my code more readable I tried to assign String.Empty to a constant value:

const string PLATYPUS_ADDED_AND_ACCEPTED = string.Empty;
if (false) { }
else
{
    toolTip = PLATYPUS_ADDED_AND_ACCEPTED;
}

but I get "the expression being added must be constant"

Isn't String.Empty always the same thing? That seems pretty constant to me.

Community
  • 1
  • 1
B. Clay Shannon-B. Crow Raven
  • 8,547
  • 144
  • 472
  • 862

1 Answers1

3

string.Empty is a readonly field, not a constant.

The compiler has no way to know this will always be the same value.

Steve B
  • 36,818
  • 21
  • 101
  • 174
  • Actually, Tim's answer is better as Tim pointed to the explanation of this choice by Microsoft. – Steve B Dec 17 '12 at 17:04