Using Shared Methods

Shared members are prevalent in Visual Basic .NET. Many of the classes in the CLR and all the methods in the base class Object are shared. Shared members are commonly employed in utility classes where it's not important to capture state. For example, you don't need to store the state of an integer to calculate the absolute value of an integer.

Classes containing all shared methods are implemented for organizational purposes more than anything. It's easy and convenient to define shared members in a class in an effort to ensure that code is more manageable. The Reset method in Listing 11.3 on lines 4 through 6 demonstrates a shared method.

Shared methods can be added to structures and classes, and it's reasonable to think of ...

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