Defining Properties

Sunday, 28 March 2010 18:11 administrator
Print PDF

Properties allow you to set and get fields using methods. Properties are a valuable feature of C# because they enable you to hide fields from your class users by making the fields private, while still giving users an easy way to get at those fields. You can think of a property as a wrapper around a private field, through which the field is accessed.


Tip

Private fields and properties promote encapsulation. You should always try to use private fields and provide access to those fields using properties, rather than using public fields. For brevity, this book doesn't always follow this rule, but you should do so in your own programs.

 

Read more...
 

Latest News

Main Menu

News