web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Dynamics 365 Community / Forums / Finance forum / Static const variables
Finance forum

Static const variables

(0) ShareShare
ReportReport
Posted on by 200

Hi,

We can access a public const variable as follows

ClassName::VariableName.

So what is the use of      "public static const" declaration

I have the same question (0)
  • Jie G Profile Picture
    on at

    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.

  • Martin Dráb Profile Picture
    237,912 Most Valuable Professional on at

    Strictly speaking constants and variables are two different things, because constants' values can't change, therefore they're not variable.

  • RDivya Profile Picture
    200 on at

    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

  • Verified answer
    Jie G Profile Picture
    on at

    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

  • Verified answer
    Community Member Profile Picture
    on at

    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.

  • Verified answer
    Martin Dráb Profile Picture
    237,912 Most Valuable Professional on at

    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.

Helpful resources

Quick Links

November Spotlight Star - Khushbu Rajvi

Congratulations to a top community star!

Forum Structure Changes Coming on 11/8!

In our never-ending quest to help the Dynamics 365 Community members get answers faster …

Dynamics 365 Community Platform update – Oct 28

Welcome to the next edition of the Community Platform Update. This is a status …

Leaderboard > Finance

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans