c# - Accessing members in your own class: use (auto)properties or not? -


I created this "question" as a community wiki, because there is no right or wrong answer. I want the community to feel about this specific problem.

When you have an example, examples of variables, and you have created properties that are buses and sets for these example variables, should you use it inside of your own class Assets, or should you always use frequency variables?

Having auto-property in C # 3.0 also makes it a difficult decision.

Use of properties:

  Public class MyClass {Private string _name; // Maybe an auto-property off-course public string name {get {return _name; } Set {_name = value; }} Public Zero Action () {string localVar = name; // ... name = "some value"; // ...}}  

Using the example variable:

  public class MyClass {Private string _name; Public string name {get {return _name; } Set {_name = value; }} Public Zero Action () {string localVar = _name; // ... _name = "someValue"; (Those people who hate members prefixes, I apologize)  

Personally, I always use the latter (example variable), because I think the qualities only Should be used by the Other classes, not the reason why I want to stay away from most auto-properties.

Of course, things change when the property setter (or gestore) does slightly more than wrapping the instance variable.

> Are there any compulsive reasons for choosing one or the other?

This is a fairly frequently asked question here which is my article which describes some issues:


Comments

Popular posts from this blog

oracle - The fastest way to check if some records in a database table? -

php - multilevel menu with multilevel array -

jQuery UI: Datepicker month format -