Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8751271
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T13:00:53+00:00 2026-06-13T13:00:53+00:00

I am trying to declare a PI constant like this: public static const double

  • 0

I am trying to declare a PI constant like this:

public static const double PI = Math.PI;

but why am I getting this error?

The constant 'Calendar.NewCalendar.PI' cannot be marked static
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T13:00:54+00:00Added an answer on June 13, 2026 at 1:00 pm

    const implies static (you don’t need an instance to reference the const value).

    I want to also add this important point: When you link against (reference) an assembly with a public const, that value is copied into your assembly. So if the const value in the referenced assembly changes, your assembly will still have the originally compiled-in value.

    If this behavior is not acceptable, then you should consider making the field a public static readonly field.

    Lib.dll, provided as binary:

    public class Foo {
        public const int HATS = 42;
        public static readonly int GLOVES = 33;
    }
    

    App.exe, references Lib.dll:

    Foo.HATS    // This will always be 42 even if the value in Lib.dll changes,
                // unless App.exe is recompiled.
    
    Foo.GLOVES  // This will always be the same as Foo.GLOVES in Lib.dll
    

    From MSDN:

    Don’t create a constant to represent information that you expect to change at any time. For example, don’t use a constant field to store the price of a service, a product version number, or the brand name of a company. These values can change over time, and because compilers propagate constants, other code compiled with your libraries will have to be recompiled to see the changes.

    From DotNetPerls:

    DLLs. When you use a const field or declaration, the C# compiler actually embeds the const variable’s value directly in the IL code. Therefore, it essentially erases the const as a separate entity.

    Caution:
    If programs that depend on a const are not recompiled after the const value changes, they may break [because they’ll continue to use the previous value].

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Im trying to declare an array in C++ but i keep getting this error.
Trying to declare this: private const string 5dfgfdgfdg = watever; But it gives me
I'm trying to declare a method in main.h like this: void buildGraph(int gNum, Graph**
I am trying to declare the border of a div using hsl() like this:
I got this error while trying to compile the below code. I would like
I'm trying to use a lambda as a static member, like this: struct A
When trying to declare a static array in my program I receive a static
I'm trying to declare a global variable from within a class like so: class
I'm trying to create a class for colors. Something like: class Color { public:
I am trying to declare a constant array for validating type properties held by

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.