C# Tutorials - Properties, Arrays, and Indexers
It's always a good goal to design classes that not only hide the implementation of the class's methods, but that also disallow any direct member access to the class's fields. By providing accessor methods whose job it is to retrieve and set the values of these fields, you can be assured that a field is treated correctly-that is, according to the rules of your specific problem domain-and that any additional processing that's needed is performed.
Table of content (tutorial index)
advertisement
Properties as Smart Fields
Defining and Using Properties
What the Compiler Is Really Doing
Read-Only Properties
Advanced Use of Properties
Arrays
Single-Dimensional Array Example
Multidimensional Arrays
Querying for Rank
Jagged Arrays
Treating Objects Like Arrays by Using Indexers
Defining Indexers
Indexer Example
Design Guidelines