O'Reilly logo

C#: A Beginner's Tutorial by Jayden Ky

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 11

Enumerations

Enums are a data type in .NET Framework that can be used to hold enumerated values. You primarily use enums to restrict the possible values that can be assigned to a variable or returned from a method.

This chapter shines a light on this data type.

An Overview of Enum

You use the keyword enum to create a set of valid values for a field or a method. For example, the only possible values for the customerType field may be Individual and Organization. For the state field, valid values may be all the states in the US plus Canadian provinces. With enum, you can easily restrict your program to take only one of the valid values.

An enum type can stand alone or can be part of a class. You make it stand alone if it needs to be used ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required