17.4. Summary

C# has three programming constructs that do not have direct equivalents in the Java world: properties, indexers, and attributes.

Properties are a façade for an object's attributes or fields. Properties provide get{} and set{} blocks, which are like the accessor and mutator methods. The code in the get{} and set{} blocks is called by the runtime transparently whenever the user of the property sets or gets the value of the property. Properties have the pros and cons shown in Table 17.2.

You should use properties only for wrapping the fields of an object so that the get and set blocks do minimal or no processing in getting and setting the value of the property.

Indexers let you use array-like notation to access a collection of objects. ...

Get .NET for Java Developers: Migrating to C# now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.