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

  • Home
  • SEARCH
  • 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 9197991
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T22:11:22+00:00 2026-06-17T22:11:22+00:00

Why are we able to write public int RetInt { get;set; } instead of

  • 0

Why are we able to write

public int RetInt
{
   get;set;
}

instead of

public int RetInt
{
   get{return someInt;}set{someInt=value;}
}

What is the difference between the two?

  • 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-17T22:11:23+00:00Added an answer on June 17, 2026 at 10:11 pm

    This feature is called Auto implemented properties and introduced with C# 3.0

    In C# 3.0 and later, auto-implemented properties make
    property-declaration more concise when no additional logic is required
    in the property accessors. They also enable client code to create
    objects. When you declare a property as shown in the following
    example, the compiler creates a private, anonymous backing field
    that can only be accessed through the property’s get and set
    accessors
    .

    class Customer
    {
        // Auto-Impl Properties for trivial get and set 
        public double TotalPurchases { get; set; }
        public string Name { get; set; }
        public int CustomerID { get; set; }
    

    For your question

    What is the difference between the two?

    In your case, none. Since you are not doing anything while setting or retrieving the value, but suppose you have want to do some validation or want to perform other types of check then :

    private int someInt;
    public int RetInt
    {
        get
        {
            if (someInt > 0)
                return someInt;
            else
                return -1;
        }
        set { someInt = value; } // same kind of check /validation can be done here
    }
    

    The above can’t be done with Auto implemented properties.

    One other thing where you can see the difference is when initializing a custom class type property.

    If you have list of MyClass
    Then in case of Normal property, its backing field can be initialized/instantiated other than the constructor.

    private List<MyClass> list = new List<MyClass>();
    public List<MyClass> List
    {
        get { return list; }
        set { list = value; }
    }
    

    In case of Auto implemented property,

    public List<MyClass> SomeOtherList { get; set; }
    

    You can only initialize SomeOtherList in constructor, you can’t do that at Field level.

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

Sidebar

Related Questions

public class Command { public int CommandId { get; set; } public string Title
It is able to write {{ myval.add:5 }} , {{ myval|add:value }} and even
Given a model like this: public class Location { public int Id { get;
public class Version { public byte Major { get; set; } public byte Minor
public class Car { public string SomeProperty { get; set; } public Manufacturer Manufacturer
Users will be able to write some documents. Those documents will consists of chapters
I am able to write a data frame to an excel file, using the
I was able to write some code with the help of the community here,
I want to be able to write to an OutputStream of a HttpServletResponse even
How would I be able to write it so that if the span says

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.