Lecture overview -- Keyboard shortcut: 'u'  Previous page: Simple types -- Keyboard shortcut: 'p'  Next page: Non-simple types -- Keyboard shortcut: 'n'  Lecture notes - all slides and notes together  slide -- Keyboard shortcut: 't'  Textbook -- Keyboard shortcut: 'v'  Help page about these notes  Alphabetic index  Course home  Page 8 : 43
Object-oriented Programming in C#
Introduction to C#
Enumerations types

Enumeration types provide for symbolic names of selected integer values. Use of enumeration types improves the readability of your programs.

Enumeration types are similar to each other in C and C#

  public enum Ranking {Bad, OK, Good}

  public enum OnOff: byte{
    On = 1, Off = 0}

Two examples of enumeration types in C#.

  • An extension of C enumeration types:

    • Enumeration types of several different underlying types can be defined (not just int)

    • Enumeration types inherit a number of methods from the type System.Enum

    • The symbolic enumeration constants can be printed (not just the underlying number)

    • Values, for which no enumeration constant exist, can be dealt with

    • Combined enumerations represent a collection of enumerations

/user/normark/oop-csharp-1/sources/c-sharp/introductory-examples/enumeration-types/ex.csDemonstration of enumeration types in C#. This program is explained

Programming with Ranking and OnOff.

/user/normark/oop-csharp-1/sources/c-sharp/introductory-examples/enumeration-types/outputOutput from the program that demonstrates enumeration types.


Go to exerciseECTS Grades
Go to exerciseUse of Enumeration types