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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T01:00:54+00:00 2026-05-18T01:00:54+00:00

I have a confusion about understanding Property and Variables public class ABC() { public

  • 0

I have a confusion about understanding Property and Variables

public class ABC()
{
    public int A;
    public int B { get; set; }
}

What is the exact difference between in A and B?

  • 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-18T01:00:55+00:00Added an answer on May 18, 2026 at 1:00 am

    As many have pointed out, A is a field, B is a property.

    The real question is, why should you care, and what to use?

    I refer to a blog post of Jonathan Aneja:

    (Its in VB, but it applies to C# as well ;))

    So why use properties over fields, 5 reasons:

    1. Fields can’t be used in Interfaces

    You can’t enforce the existence of a
    field in an object’s public contract
    through an interface. For properties
    though it works fine.

    2. Validation

    While your application currently may
    not require any validation logic to
    set a particular value, changing
    business requirements may require
    inserting this logic later. At that
    point changing a field to a property
    is a breaking change for consumers of
    your API. (For example if someone was
    inspecting your class via reflection).

    3. Binary Serialization

    Changing a field to a property is a
    breaking change if you’re using binary
    serialization. Incidentally, this is
    one of the reasons VB10’s
    auto-implemented properties have a
    “bindable” backing field (i.e. you can
    express the name of the backing field
    in code) – that way, if you change an
    auto-implemented property to an
    expanded property, you can still
    maintain serialization compatibility
    by keeping the backing field name the
    same (in C# you’re forced to change it
    because it generates backing fields
    with unbindable names).

    4. A lot of the .NET databinding infrastructure binds to properties but not fields

    I’ve heard arguments on both sides as
    to whether or not that’s a good thing,
    but the reality is that’s the way it
    works right now. (Note from me: WPF bindings work on properties)

    5. Exposing a public field is an FxCop violation

    For many of the reasons listed above
    🙂

    There might be more reasons.

    I would also like to point to a blog post of Jeff Atwood and conclude with a quote from it:

    The really important thing to take away here is to avoid writing code that doesn’t matter. And property wrappers around public variables are the very essence of meaningless code.

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

Sidebar

Related Questions

I have confusion about GridView in ASP.NET. How does the GridView exactly work? I
mmm, I have just a little confusion about multiple auto declarations in the upcoming
I have some confusion about when to use the self keyword during ivars assignment,
I have bit confusion about parameters. When we should have to use reference parameter
All, I Have a small confusion about Case sensitivity of ODBC DSN names. Say,
I have a little bit of confusion about iOS Apps publication. The first time
I think I may have some confusion about the domain/service layer separation. In my
This is probably a very simple question but I have a confusion about the
I have some confusion related to the .NET platform build options in Visual Studio
I am sorry about the amount of code here. I have tried to show

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.