Notifications
Announcements
No record found.
Hi,
We can access a public const variable as follows
ClassName::VariableName.
So what is the use of "public static const" declaration
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.
Strictly speaking constants and variables are two different things, because constants' values can't change, therefore they're not variable.
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
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
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.
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.
Under review
Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.
Congratulations to a top community star!
In our never-ending quest to help the Dynamics 365 Community members get answers faster …
Welcome to the next edition of the Community Platform Update. This is a status …
Stay up to date on forum activity by subscribing.