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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T17:54:36+00:00 2026-06-17T17:54:36+00:00

I’ve been wondering about this for a while and haven’t been able to find

  • 0

I’ve been wondering about this for a while and haven’t been able to find much commentary on the subject and haven’t been able to come on a conclusion by myself.

When creating objects, it’s accepted best practice to make the object as limited as possible in terms of exposing data and allowing that data to manipulated. If you can make an object immutable, especially in multi-threaded applications, then it is best to do so.

Having said that, C# seems to favor the developer who doesn’t follow this rule by allowing the definition of a class to be much more simple, and more importantly, easier to maintain.

Take the following read-only immutable class:

public class ActiveDirectoryUser
{
    private readonly string firstName, lastName, office, username, email;

    public ActiveDirectoryUser(string firstName, string lastName, string office, string username, string email)
    {
        this.firstName = firstName;
        this.lastName = lastName;
        this.office = office;
        this.username = username;
        this.email = email;
    }

    public string FirstName
    {
        get { return firstName; }
    }

    public string LastName
    {
        get { return lastName; }
    }

    ...

    public string Email
    {
        get { return email; }
    }
}

And compare it to the much more simple example as below, which isn’t read-only.

public class ActiveDirectoryUser
{
    public string FirstName
    {
        get;
        set;
    }

    public string LastName
    {
        get;
        set;
    }

    ...

    public string Email
    {
        get;
        set;
    }
}

Which can be instantiated with the following is:

ActiveDirectoryUser user = 
    new ActiveDirectoryUser
       { FirstName= "Sam", LastName = "Shiles", ..., Email ="Sam@shiles.com" };

Given the simpler definition, the fewer lines of code, the less chance for developer error and the ease with which another developer can understand the code (especially with examples that are more true to life than our simple example), is the value of creating proper read-only, immutable objects, worth the cost?

Also, do other people believe that making immutable objects in C# should be made easier with an automatic-esq syntax such as:

public string FirstName {get; readonly set;}
  • 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-17T17:54:38+00:00Added an answer on June 17, 2026 at 5:54 pm

    Given the simpler definition, the fewer lines of code, the less chance for developer error and the ease with which another developer can understand the code (especially with examples that are more true to life than our simple example), is the value of creating proper read-only, immutable objects, worth the cost?

    Yes.

    I note that nothing is stopping you from saying

    int Foo { get; private set; }
    

    and then using the setter only in the constructor, to guarantee immutability of the property. You just don’t get the nice object initializer syntax, but you could create a constructor easily enough.

    Also, do other people believe that making immutable objects in C# should be made easier with an automatic-esq syntax…

    Yes. In particular, the C# language design team believes that.

    C# 3.0 added a number of features that make C# a more “immutable-friendly” language: anonymous types, query comprehensions and expression trees in particular encourage an immutable-data “functional” style of programming. It also added features that make C# a more “mutable-friendly” language: automatic properties, object initializers and type-inferred arrays come to mind.

    The language design team is well aware that these latter features have made it easier to create mutable objects at the same time as the DLR team was making a huge library of immutable expression tree types. The irony was not lost on them, I can assure you.

    There are many proposals floating around the language design team for better syntactic sugars for making immutable objects. The fact that object initializers, which require mutability, have almost identical syntax as anonymous type initializers, which are immutable, is an obvious starting point for exploration, but not the only one.

    All that said, of course, first, I no longer speak on behalf of the language design team, and second, there is no announced future version of C# beyond the Roslyn project. Thus, speculation as to possible feature sets for hypothetical future versions of the language is just that: speculation on my part.

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

Sidebar

Related Questions

I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I don't have much knowledge about the IPv6 protocol, so sorry if the question
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have a jquery bug and I've been looking for hours now, I can't
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,
I am trying to find ID3V2 tags from MP3 file using jid3lib in Java.
I have this code to decode numeric html entities to the UTF8 equivalent character.

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.