Skip to main content

Notifications

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

  • Verified answer
    Martin Dráb Profile Picture
    232,183 Most Valuable Professional on at
    RE: Static const variables

    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.

  • Verified answer
    Community Member Profile Picture
    on at
    RE: Static const variables

    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
    Jie G Profile Picture
    on at
    RE: Static const variables

    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

  • RDivya Profile Picture
    200 on at
    RE: Static const variables

    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

  • Martin Dráb Profile Picture
    232,183 Most Valuable Professional on at
    RE: Static const variables

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

  • Jie G Profile Picture
    on at
    RE: Static const variables

    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.

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

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 293,311 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 232,183 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,158 Moderator

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans