public const problem

  • Thread starter Thread starter Mike P
  • Start date Start date
M

Mike P

I don't understand why when using

class Consts
{
public const string Var = "Hello"
}

The value of Consts.Var within the debugger is null, but at runtime it is
correct (holds the value "Hello")

I was able to get around the problem by using
public static readonly string Var = "Hello", but you can't use

Consts.Var in a switch because it is not a constant.

Any ideas?
 
The value of Consts.Var within the debugger is null, but at runtime it is
correct (holds the value "Hello")

Constants aren't loaded at runtime since they are only used at compile
time, that may be why it doesn't show as expected in the debugger.



Mattias
 
Back
Top