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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T14:37:06+00:00 2026-05-13T14:37:06+00:00

Seen a few examples of code where this happens: public class Foo { string[]

  • 0

Seen a few examples of code where this happens:

public class Foo
{
    string[] m_workID;
    public string[] WorkID
    {
        get
        {
            return m_workID;
        }
        private set
        {
            m_workID = value;
        }
    }
}

What’s the point of this?
Since the use m_workID unnescessary.

  • 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-05-13T14:37:06+00:00Added an answer on May 13, 2026 at 2:37 pm

    In general, the point is to separate implementation (the field) from API (the property).

    Later on you can, should you wish, put logic, logging etc in the property without breaking either source or binary compatibility – but more importantly you’re saying what your type is willing to do, rather than how it’s going to do it.

    I have an article giving more benefits of using properties instead of public fields.

    In C# 3 you can make all of this a lot simpler with automatically implemented properties:

    public class Foo
    {
        public string[] WorkID { get; private set; }
    }
    

    At that point you still have a public getter and a private setter, but the backing field (and property implementation) is generated for you behind the scenes. At any point you can change this to a “normal” fully-implemented property with a backing field, and you’ll still have binary and source compatibility. (Compatibility of serialized objects is a different matter, mind you.)

    Additionally, in this case you can’t mirror the behaviour you want (the ability to read the value publicly but write it privately) with a field – you could have a readonly field, but then you could only write to it within the constructor. Personally I wish there were a similar shorthand for this:

    public class Foo
    {
        private readonly int id;
        public int Id { get { return id; } }
    
        ...
    }
    

    as I like immutable types, but that’s a different matter.

    In another different matter, it’s generally not a good idea to expose arrays like this anyway – even though callers can’t change which array WorkID refers to, they can change the contents of the array, which is probably not what you want.

    In the example you’ve given you could get away without the property setter, just setting the field directly within the same class, but it would mean that if you ever wanted to add logging etc you’d have to find all those writes.

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

Sidebar

Ask A Question

Stats

  • Questions 311k
  • Answers 311k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Tango has a few simple functions for converting between ANSI… May 13, 2026 at 10:21 pm
  • Editorial Team
    Editorial Team added an answer Typically it will run for 20 min because that is… May 13, 2026 at 10:21 pm
  • Editorial Team
    Editorial Team added an answer As far as I can see, you need to add… May 13, 2026 at 10:21 pm

Related Questions

Hopefully a picture is worth a thousand lines of code because I don't want
This is a little subjective I think; I'm not sure if the opinion will
I'm sure more than a few of you will have seen the Google Wave
I was reading some things about exception handling in Java, to be able to
I think I've become quite good at the basics of programming (for a variety

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.