Announcements
Hi,
We can access a public const variable as follows
ClassName::VariableName.
So what is the use of "public static const" declaration
There would be a no point in maintaining a copy of a constant separately in every instance, if the values must always be the same.
Hi,
The const objects are static.
You don't need to write public static const,
write as public const str testValue = "test1";
Only specify your access modifier - public, private, protected, internal.....
If you want a variable then declare static.
Hello,
According to my test and official document, the constants can then be referenced by using the double-colon syntax no matter you declare it with a static or not.
Please refer the Consts/Readonly section in this link: docs.microsoft.com/.../new-x-debugger-features
Hi Martin,
I would like to know if its required to declare static const.
We can only use const instead of static const since const is going to be accessed using className.
Thanks
Strictly speaking constants and variables are two different things, because constants' values can't change, therefore they're not variable.
Hello,
Public means this variable can be used outside the class.
Static means this is a static method or field, you can use it without initialize an instance of the class.
Const means this variable is a const, which allows you to define members on a class and variables in a method that can only be initialized during the declaration. The compiler will replace references to these constants with the literal value. In other words, the constant value must be known at compile time.
André Arnaud de Cal...
293,311
Super User 2025 Season 1
Martin Dráb
232,183
Most Valuable Professional
nmaenpaa
101,158
Moderator