c# - Is code cleanliness a good enough reason to use a property over a field? -


I have a class that has been empowered to allow subscriptions to the list contained in it, for this reason, the list There is no need to reach public through an area or property.

  Public category foo: IEnumerable & lt; Bars & gt; {Private list & lt; Bars & gt; _positions;  

If I have other properties in my class with the private setters, then future programmers will be able to Pascal Seyes , Pascal Seyes Pascal Season , _asdfghjk . Isn't it? What was he nonsense? _asdfghjk definitely looks pretty ugly.

Like _positions

  private list and <; Bars & gt; Posts {received; Set; }  

Is there enough reason enough to use the property on the field?

Unless you coherent then no one is surprised to read your code Will happen.

If the code you are using is _privateField as long as you are using it everywhere, the person reading your code will use it.

The danger comes when you mix styles.

To be honest, personally I am confused to find a private automatic recipient / setter property in a class; To quote MSDN:

Enables a class to display a public method of attaching values ​​and setting values ​​when hiding the verification code is.
- Generally, you should only use the field for the variable in which Private or access. In the end, if you start the field with an underscore, then this warning: - -

P>

Field names should not start with underscore. [Stylecop Rules: SA130 9]


Comments

Popular posts from this blog

python - Overriding the save method in Django ModelForm -

html - CSS autoheight, but fit content to height of div -

qt - How to prevent QAudioInput from automatically boosting the master volume to 100%? -