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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T07:01:47+00:00 2026-06-09T07:01:47+00:00

Possible Duplicate: What is the difference between a field and a property in C#

  • 0

Possible Duplicate:
What is the difference between a field and a property in C#

I’m a beginning programmer and I’ve read all about class properties. Books state that properties allow you to indirectly access member variables. Ok, so what makes it any different than just making the field public and accessing it directly?

Here’s a quote from Learning C# 3.0 by Jesse Liberty:

For example, you might want external
classes to be able to read a value, but not change it; or you might want to write
some code so that the internal field can accept only values in a certain range. If you
grant external classes free access to your member fields, you can’t control any of that.

I don’t understand what he is saying here. Can someone further explain this or give an example of why I would want to use a property over making the field public. As I understand it now they would both accomplish the same exact thing…so I’m obviously missing something here.

  • 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-09T07:01:49+00:00Added an answer on June 9, 2026 at 7:01 am

    Properties can have side-effects, They provide syntactic sugar around ‘getter’ and ‘setter’ methods.

    public class MyClass {
    
       int sizeValue = 0;
    
       public int Size {
          get {
             return sizeValue;
          }
          set {
             if ( value < 10 ) throw new Exception("Size too small");
             sizeValue = value;
          }
       }
    }
    

    Properties can also have different levels of protection for get and set, you cannot do that with fields.

    public class MyOtherClass {
    
       // only this object can set this.
       public int Level {
          get; private set; 
       }
    
       // only things in the same assembly can set this.
       public string Name {
          get; internal set;
       }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Difference between Property and Field in C# public class Test { public
Possible Duplicate: Difference between Property and Field in C# I thought that basic properties
Possible Duplicate: What is the difference between a field and a property in C#
Possible Duplicate: What is the difference between a field and a property in C#?
Possible Duplicate: What is the difference between a field and a property in C#
Possible Duplicate: Difference between @import and link in CSS I've read about CSS @import
Possible Duplicate: Difference between Color.red and Color.RED I have seen that the Java class
Possible Duplicate: difference between throw and throw new Exception() I'm a programmer working on
Possible Duplicate: Difference between using var and not using var in JavaScript Hi All
Possible Duplicate: Difference between single quote and double quote string in php Hi all

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.