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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T15:31:30+00:00 2026-05-13T15:31:30+00:00

I’m comming from Java world mainly. So, C# properties do look nice. I know

  • 0

I’m comming from Java world mainly. So, C# properties do look nice.

I know that with C# 3.0 or above I can use Automatic Properties. I like it even more :).

My question is about a (maybe older) code where I can see this:

   private int age;

   public int Age {

     get { return age; }
     set { age = value; }     
   }

Why do I need the private field age? What I’m I really hiding here?

EDIT:

I completely understand the need for the getter and setter. I mentioned that I’m comming from Java world and doing this all the time.

I do understand that Automatic Properties in C# 3.0 or above are syntatic sugar. But maybe my question has a simpler answer. Does it means that (bellow C# 3.0) the property doesn’t hold any value. So it must get the value from some other field?

  • 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-13T15:31:30+00:00Added an answer on May 13, 2026 at 3:31 pm

    Older versions of C# didn’t have automatic properties, so you had to declare your variables that the properties acted upon like in your example. These days, the same code could be expressed as:

    public int Age { get; set; }
    

    I think that answers your question. However, if you are asking “why not just have public int Age; and let programmers set the value on the field directly?”, then:

    First thing to keep in mind is that property accessors are compiled into methods. This means that it has a different ABI from just reading/writing to a class member variable, even though it may syntactically look the same as if you had:

    class Fu {
      public int Age;
    }
    

    So, what this means is that if, at some point down the road, you need to add some notification that the Age field has changed – if you are using properties, you can easily add this notification logic to the property setter without breaking ABI.

    public int Age {
      get { return age; }
      set { age = value; NotifySomeOtherCode (); }
    }
    

    If you start off with a public field, then later changing it to a property will change the ABI which is bad for any program(s) that may depend on your assembly. So it’s better to start off with properties.

    Hopefully I’m making sense…

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

Sidebar

Ask A Question

Stats

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

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

    • 7 Answers
  • Editorial Team

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

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Lots of reads in every query, fewer regular writes Both… May 14, 2026 at 11:46 pm
  • Editorial Team
    Editorial Team added an answer You can use stored procedure with output parameter (or return… May 14, 2026 at 11:46 pm
  • Editorial Team
    Editorial Team added an answer Using a file template is definitely the best solution. For… May 14, 2026 at 11:46 pm

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.