Enumerations

Let's assume you have been given the task of writing a subsystem for a game of cards (like bridge, for example). Your task is to determine if a given card from the deck was used already. That means you need some means to represent the deck of cards and remember for each card if it was used or not. A deck of cards consists of 52 cards divided into 4 suits (clubs, diamonds, hearts, and spades). Each suit consists of the cards from 2 to 10, the Jack, Queen, King, and Ace of the suit.

To store the fact that a card was used you can use an array of 52 Boolean values. Or even better (more intuitive) you could use a two-dimensional array of 4 rows (one per suit) and 13 columns (one for each card in the suit). Deciding that you use the latter ...

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