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 951913
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T23:48:38+00:00 2026-05-15T23:48:38+00:00

I have a class Constants in which I store a number of static readonly

  • 0

I have a class Constants in which I store a number of static readonly variables.

Should I do this:

private static readonly int _maxThings = 100;
...
public static int MaxThings { get { return _maxThings; } }

That seems kind of redundant to me. Is there any reason why I wouldn’t just do the following?

public static int MaxThings { get { return 100; } }

Edit

Okay, so this was a brain fart of a question. I think the point is that if I’m going to be setting this value at initialization then it makes sense to use a static backing field and expose a public get-only property that wouldn’t need to be static itself.

If, however, I’m comfortable setting a public static property to a hard value, then there’s no functional difference between that and just baking it into the assembly. Unless there’s some other concept I’m missing here, in this case I’d just use a const.

Thanks for the answers.

  • 1 1 Answer
  • 4 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-05-15T23:48:38+00:00Added an answer on May 15, 2026 at 11:48 pm

    you should do

    public const int MaxThings = 100;

    there is no reason that i can see to use properties in this case.

    Update ->

    In response to comments.. If you are developing a library and exporting constants then it’s important to understand how constants are consumed int .net. When compiled against your library, the constant values will be inlined and included in the consuming application, such that if your library is updated and consuming application is not then the old constant values will still be present. This is, of course, when static properties should be used.

    If you are not developing a library, then the use of const’s are fine.

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

Sidebar

Related Questions

I have a C++ class implementation file which has some constants. The constants appear
I have a Model which has some constants defined, like below: class Order(models.Model): WAITING
I have the following construction: public static class Constants { public static class Foo
I have written a class (AbcdBase) which holds several static objects, these include maps
Let's say I have objects which look very roughly like this: class object {
I have a class which is essentially just holds a bunch of constant definitions
I have a Class named Constants that contains all the constant variable in my
I have a base class A with a constant static variable a. I need
I have a question on constant objects. In the following program: class const_check{ int
I've got a static class containing a static field which makes reference to a

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.