Enum: Difference between revisions

From Computer Science Wiki
(Created page with "An "enum" (short for "enumerated type") is a data type that consists of a set of named values. It is used to represent a set of distinct, named values in a program, making it easier to read, maintain, and avoid bugs. For example, in a program that tracks the days of the week, an enum could be used to represent the days of the week instead of using raw integers or strings. Enums can be found in many programming languages, including Rust, C++, and C#.<ref>ChatGPT</ref> I...")
 
Line 20: Line 20:


== References ==
== References ==
</references>

Revision as of 09:07, 4 February 2023

An "enum" (short for "enumerated type") is a data type that consists of a set of named values. It is used to represent a set of distinct, named values in a program, making it easier to read, maintain, and avoid bugs. For example, in a program that tracks the days of the week, an enum could be used to represent the days of the week instead of using raw integers or strings. Enums can be found in many programming languages, including Rust, C++, and C#.[1]


In computer programming, an enumerated type is a data type consisting of a set of named values called elements, members, enumeral, or enumerators of the type. The enumerator names are usually identifiers that behave as constants in the language. An enumerated type has values that are different from each other, and that can be compared and assigned, but are not specified by the programmer as having any particular concrete representation in the computer's memory; compilers and interpreters can represent them arbitrarily.[2]


enum DayOfWeek {
    Monday,
    Tuesday,
    Wednesday,
    Thursday,
    Friday,
    Saturday,
    Sunday,
}


References