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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T00:40:04+00:00 2026-05-13T00:40:04+00:00

my question is simple, is using the get set properties of C# considered good,

  • 0

my question is simple, is using the get set properties of C# considered good, better even than writing getter and setter methods? When you use these properties, don’t you have to declare your class data members as public ? I ask this because my professor stated that data members should never be declared as public, as it is considered bad practice.

This….

class GetSetExample
{
    public int someInt { get; set; }
}

vs This…

class NonGetSetExample
{
    private int someInt;
}

Edit:

Thanks to all of you! All of your answers helped me out, and I appropriately up-voted your answers.

  • 1 1 Answer
  • 2 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-13T00:40:04+00:00Added an answer on May 13, 2026 at 12:40 am

    This:

    class GetSetExample
    {
        public int someInt { get; set; }
    }
    

    is really the same as this:

    class GetSetExample
    {
        private int _someInt;
        public int someInt {
            get { return _someInt; }
            set { _someInt = value; }
        }
    }
    

    The get; set; syntax is just a convenient shorthand for this that you can use when the getter and setter don’t do anything special.

    Thus, you are not exposing a public member, you are defining a private member and providing get/set methods to access it.

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

Sidebar

Related Questions

What is considered good practice for querying entites from a database using a simple
Simple question.. just can't get the result set in the order I need :p
I have what I hope is a fairly simple question about using the value
I just gave an answer to a quite simple question by using an extension
Simple question :) How can I reduce build time using a parallel build /
Simple question but cannot find answer anywhere. When using a MS Chart Control of
Hopefully a simple question although one I have found impossible to answer myself using
Very simple question, but I want to start using a consistent naming convention for
I am using Polymorphic Models . Simple Question: My code below works without using
This is a simple question really. I've been using the new type of constructors

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.