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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T15:31:38+00:00 2026-06-09T15:31:38+00:00

Today I found out that VS offers an automatic way to define setters and

  • 0

Today I found out that VS offers an automatic way to define setters and getters. To make it crystal clear I have a simple class Students:

 class Students
    {
        private string name;
        private Int32 pin;
        private string addres;
        private int phone;
     ...

And when I select name and click ctrl +k, x then select C# and then propg I get:

   class Students
    {
        private string public int MyProperty { get; private set; }
        private Int32 pin;
        private string addres;
        private int phone;

There is obviously a problem with the code like this so I end up with :

   class Students
    {
        private string name { get; private set; }
        private Int32 pin;
        private string addres;
        private int phone;

My question is – is this the right way to get advantage of the VS automisation for getters and setters? What is the right syntax for setting and getting the value of name? If this code is correct is there a more elegant way to use VS to create my getters and setters instead of the one I found out?

  • 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-09T15:31:40+00:00Added an answer on June 9, 2026 at 3:31 pm

    The idea behind automatic properties is to remove the private fields entirely, and replace them with automatic properties (which have a hidden backing field).

    There’s also a code snippet

    prop (TAB TAB)
    

    That said, you should consider making get / setters public, and the usual convention is to PascalCase property names, viz.

    class Students
    {
        public string Name { get; set; }
        public Int32 Pin { get; set; }
        public string Address { get; set; }
        public int Phone { get; set; }
       ...
    

    EDIT
    As per Servy’s comment, there is a growing movement toward making data-centric classes like DTO’s immutable. This would result in making the setters private, and providing an initialization constructor and / or class factory method to the class. But that is something for later 🙂

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

Sidebar

Related Questions

Today, I found out that you can write such code in C++ and compile
I found out today that GetWindowLong (and GetWindowLongPtr ) has 'ANSI' (A) and 'Unicode'
Found out today that Twitter will be discontinuing its basic authentication for its API;
Today only I have noticed and found out the importance of using === operator.
Today I found out that putting strings in a resource file will cause them
We have enabled the NoTrackingReleasePolicy on our windsor containers, and today I found out
So I just found out today that you can use <base href=/> to specify
So I just found out today that Log4J 2.0 is now actively being developed,
So I found out today that structs and classes act differently when used to
We found out today that for two of our customers, JavaMail is not authenticating

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.