|
| public static readonly string Foo = "bar"; |
| |
| public static void Main(){ |
| string f = "bar"; |
| switch(f){ |
| case Foo: |
| break; |
| } |
| } |
error CS0150: A constant value is expected
Cannot convert expression of type 'string' to type 'string'
I have a public static readonly string, and I want to use it as a case in a switch statement, as above. Unfortunately for me, C# doesn't
think a public static readonly string is a constant value. I guess it's not constant, as it changes from its compile time
value (null?) to its runtime value ("bar") once it gets referenced. This is retarded. What if I wanted to store constant values in the
web|app.config? Those aren't determined until runtime when I pull them out of ConfigurationSettings.AppSettings.
Oh wait, that is such a time-saver! Now I don't have to even consider solutions using runtime constants in case statements.
Thanks, C# language developers, you've limited my options once again, steering my foolish code down the path you know is best!