Shared Members versus Instance Members

Shared members have existed in other languages such as C++ and Java for years and are a very welcome addition to Visual Basic. In C#, C++, and Java, shared members are called “static” members. It would be easy to argue that the term “shared” used by Visual Basic .NET is more concise and more in line with reality. That's because the shared members of a class are actually shared across every object created from that class.

Chapter 3 introduced the concept of shared members. Recall that certain members of a type can be associated with the type itself as opposed to being associated with an instance of the type. Let's look at Listing 4.3, which shows a class with two fields—one instance and one shared.

Listing ...

Get Building Applications and Components with Visual Basic .NET 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.