Reputation: 47945
I have the following code:
public class iSito
{
public const string myVar = "5262";
public iSito()
{
}
}
Now, if from any context (in my case, a .ascx.cs) I try to use iSito.myVar, I can't get any value.
Why?
Upvotes: 3
Views: 5889
Reputation: 56934
Is the iSito class in another DLL / assembly ? If so, have you rebuild the DLL and have you rebuild the application that consumes the DLL ?
A const value is written as a literal in the IL when you compile the client application. If you change the const, you'll have to rebuild the client app.
What happens if you change the const to be readonly ? (Just for testing purposes).
Upvotes: 6
Reputation: 160852
Your example is correct and should work - consts are automatically static, so you can access the field as iSito.myVar
- make sure you qualify with the full namespace, same as needed to access the class (or add an appropriate using statement).
Upvotes: 11