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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T03:13:34+00:00 2026-06-07T03:13:34+00:00

having code like this: public static readonly bool MaximumRecipientsReached; private static readonly IList<EmailAddress> Contacts;

  • 0

having code like this:

    public static readonly bool MaximumRecipientsReached;
    private static readonly IList<EmailAddress> Contacts;

    static AdditionalRecipient()
    {
        Contacts = AnotherClass.Contacts; //works
    }

    public AdditionalRecipient()
    {
        MaximumRecipientsReached = true; //works not
    }

Why can I change a private static readonly field but not a public one?

PS: of course I am using properties.

  • 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-07T03:13:35+00:00Added an answer on June 7, 2026 at 3:13 am

    In your first example, you are changing it in the static constructor, which is allowed, if you changed it in any other static method/property, it would be a compiler error.

    In your second example, you are attempting to change a static readonly member in a non-static constructor, which isn’t allowed.

    You can only change static readonly members in the static constructor. Think of it this way, the static constructor runs once, and after that for each instance the instance constructor is invoked. The property wouldn’t be very readonly if every instance could change it.

    You can, of course, change non-static readonly instance members in the constructor:

    public static readonly bool MaximumRecipientsReached = false;
    public readonly bool MyInstanceReadonly = false;
    
    static AdditionalRecipient()
    {
        // static readonly can only be altered in static constructor
        MaximumRecipientsReached = true; 
    }
    
    public AdditionalRecipient()
    {
        // instance readonly can be altered in instance constructor
        MyInstanceReadonly = true;  
    }
    

    Also, I’m confused by your “PS: of course I am using properties”. Properties cannot be declared readonly, if you wanted these to be properties and to be readonly-ish, you’d need to make them private set – unless of course you are using a backing field. The main reason I bring this up is because using a property with a private set would allow you to do what your code is trying to do, as the class itself can change the property (static or instance) in any method or constructor, but code outside of the class can not.

    // public getters, private setters...
    public static bool MaximumRecipientsReached { get; private set; }
    public static IList<EmailAddress> Contacts { get; private set; }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How do I avoid requiring code like this: public static class BusinessLogicAutomapper { public
I am having an issue converting type. I was trying code like this (minimal,
I have extended IDictionary like this: public static T ToClass<T>(this IDictionary<string, string> source) where
I'm building a website and having some problem. if the HTML code is like:
How to convert the text file through vb6 code. Having filename like clock.fin, time.mis,
How to copy the text file through vb6 code. Having Source filename like clock.fin,
I find myself having a lot of this in different methods in my code:
In java <1.5, constants would be implemented like this public class MyClass { public
I am kind of tired of having all this useless noise in my code:
I have a lot of code like this in one of my projects (from

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.