Useful Methods from System.Enum

As mentioned at the beginning of this section, all enumerations derive from the System.Enum class. Such a type exposes some shared methods that enable performing operations on enumerations. This subsection explains how you can take advantage of methods for working on enumerations.

GetValues and GetNames

The first two methods described are GetValues and GetNames. Both enable retrieving an array of items stored within an enumeration, but GetValues gets an array of integers corresponding to the numeric values of enumerations’ items whereas GetNames retrieves an array of strings storing the names of enumerations’ items. Continuing the example of the Sports enumeration, consider the following code:

This code’s output ...

Get Visual Basic 2010 Unleashed now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.