public const problem

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?
 
M

Mattias Sjögren

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top