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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T11:49:25+00:00 2026-05-22T11:49:25+00:00

When initializing members in a C# class which also have Properties with full access

  • 0

When initializing members in a C# class which also have Properties with full access (get, set), is it convention to initialize them inside the constructor via their Property method or directly by their member variable?

public class Car
{
    private string _brand;

    public Car(string brand)
    {
        // this
        _brand = brand;
        // or that
        Brand = brand;  
    }

    public Brand { get { return _brand; } set { _brand = value; } }
 }
  • 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-22T11:49:26+00:00Added an answer on May 22, 2026 at 11:49 am

    You should set the value using the Property and not the member variable. This way you can change the implementation of your “setter” and only have to modify the your code in one place.

    For example, if you discover a requirement that on setting the brand you have to also update some other property, the brand has a default colour for example, you can do this all in your set{…} block of the Brand property. If you set the value of _brand in your contructor, you’ll now have to either manually update the Colour property in the constructor as well, or update your constructor to now initialise the Brand property instead of the field.

    Also, where your property is that simple it’s more conventional to use an “auto property”

    public Brand { get; set; }
    

    I’d only use a backing field if you need to perform more logic than a simple property set and get.

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

Sidebar

Related Questions

I have a Message class which parses text messages using lookup tables. I receive
I have a large C structure (about 40 members, int and char[]) which I
I have a doubt about initializing string with synthesize keyword. In my Event.h class
I've got a static class member which is some container, like (Foo.h) class Foo
I’ve read that instead of initializing inherited members ( _c1 in our example )
What is the best practice for initializing an ArrayList in Java? If I initialize
I have read this document Initializing static array of strings (C++)? and tried to
When it comes to allocating and initializing objects that are declared @properties of a
I have connection.php file where i am initializing PDO in the $db. And i
I'm building some classes for working with playing cards. I have a Card class

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.