Shared Properties

In an object-oriented approach, fields should be wrapped by properties that gain access to fields. This happens also with shared members. Continuing with the preceding example, a shared property would be implemented as follows:

image

In this case the property is also marked as read-only because its value is incremented only when a new instance of the class is created, passing through the related field, but of course shared properties support both Get and Set. Because the preceding code offers a read-only property, you cannot take advantage of the new auto-implemented properties feature. If you do not need a read-only property, you ...

Get Visual Basic® 2010 Unleashed 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.