What is difference between assigning to auto-Implemented properties VS their backing fields within the class

Loading ....

Software https://softwareengineering.stackexchange.com/questions/387715/what-is-difference-between-assigning-to-auto-implemented-properties-vs-their-bac

Before I started using auto-implemented possessions, I had been taught that when assigning properties in the constructor (due to the possibility of building a property read only)I should assign right to the private member to your house (which we’d usually name together with the house’s name with an underscore before it. EX: _propertyName.)

When I shifted to using auto-implemented properties, I kept the clinic, so much as establishing that just the members ought to be referenced within the class of the property. I understand these auto-implemented private members are known as”Backing Fields”.

I think it is fascinating that they are invisible until typed, to intellisense. Further, I made the observation that if you auto-implement the property, it appears as though you can assign to some Read Just property within the property’s class.

Thinking about the changes that have happened in the .net frame, I’m beginning to wonder what is your”Right” way to deal with house’s from within the course. I know that is rather subjective, however I wonder are there downsides to how this has been done by me? So I am left with a couple questions about how this works, and also exactly what the consequences on my software’s design (however modest ) are:

  1. Does calling the auto-implemented property from inside property’s class call the Get and Set?
  2. Does the house’s backing field bypass this?
  3. Am I wasting (yet few) processor cycles by utilizing the property instead of the backing area?
  4. Or am I exposing myself to a potential problem in the future by using the backing fields?

Or just put:

What is difference between delegating to auto-Implemented properties VS assigning directly to their backing fields?

It seems this question nearly straddles Stack Overflow and Software Engineering depending on how you word it. Please allow me to know if I use it or need to alter the wording.



Loading ....

Originally posted 2019-02-26 01:05:17. Republished by Blog Post Promoter

Be the first to comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.