c# - Public Fields versus Automatic Properties -
We are often told that we have encapsulated rather than making garter and setter methods (properties in C #) in the field of the classroom To protect fields outside the world should be protected.
But sometimes a field is just enough to catch a price and no calculation is required to get or set it. We do all this for them:
public class book {Private string _ title; Public string title {get {return _title; } Set {_title = value; )}}
Well, I have a statement, I can not write all this (in fact, it was not to write it, to see it), so I got scared and Used.
Then comes with C # 3.0 and I think they add automatic properties:
public square book {public string title {get; Set,}}
Which is too much, and I am grateful for it, but in reality, what is different from just creating a public sector?
public class book {public string title; }
I had some time ago, but there was a link to post on Jeff Blogs, explaining some differences.
Changing a variable in a property is to change a subversion for example:
TryGetTitle (External book. Title); // should have a variable
Comments
Post a Comment