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

  • Home
  • SEARCH
  • 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 8090471
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T19:44:03+00:00 2026-06-05T19:44:03+00:00

My class contains LOT_SIZE constant which can not be changed. But I can initialize

  • 0

My class contains LOT_SIZE constant which can not be changed. But I can initialize it only during execution, because I obtain LOT_SIZE from Securities table at runtime. However I want to make clear that this is constant and I want to protect it from changes from any other places except one “friend” place where I want to initialize it (“Securities” table read).

Do we have something for that in C# or I just have to use LOT_SIZE as regular variable?

I can not declare LOT_SIZE as readonly because during object construction “Securities” table still not read and so I don’t know LOT_SIZE value.

  • 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-05T19:44:05+00:00Added an answer on June 5, 2026 at 7:44 pm

    The best way is probably to read the value before creating the class that must hold it, so you can pass it into the constructor and put it into a readonly field. But as you’ve excluded doing it the obvious way…

    You could use a read-only property (a property with a get but no set) and always access it via the property except in the place where you initially set up the value.

    If you don’t even want to risk changing it from within your own class, then create a class to “wrap” the value. This class would do nothing more than read the value when required the first time and expose it as a read-only property to your consumer classes.

    But whichever way you choose, please don’t use “1970’s C macro constant” (ALL_CAPS) naming for your constant 🙂

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

Sidebar

Related Questions

Can I get an element if its class contains some text? Example: <div class=headerbody></div>
I have a class named AllStatStruct. This class contains three attributes, which are objects
I have a Singleton which has an NSMutableArray containing a Class, the Class contains
I have a class contains 10 methods which are doing almost the same things
My project contains a lot of classes, a bunch of which can be described
So assume I have one class named Program which contains my whole program of
Is facade a class which contains a lot of other classes? What makes it
I have a java package which contains all my test case classes. Each class
I have a base windows forms class which contains two buttons: Ok and Cancel.
I have a Sql Utility class which contains a lot of handy methods around

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.