- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Enumerations in Dart Programming
An enumeration is a set of predefined values. These values are known as members. They are useful when we want to deal with a limited set of values for the variable. For example, you can think of the number of days in a week - Monday, Tuesday, Wednesday etc.
An Enumeration can be declared using the enum keyword.
Syntax
enum <enum_name> { const1, const2, …. constN }
Let's define an enumeration for the number of colors in a traffic light −
enum TrafficLights { Red, Green, Yellow }
Now, let's see how we can make use of an enumeration in a Dart program.
Example
Consider the example shown below −
enum TrafficLights { Red, Green, Yellow } void main(){ print(TrafficLights.values); TrafficLights.values.forEach((x) => print('value : $x')); }
Output
[TrafficLights.Red, TrafficLights.Green, TrafficLights.Yellow] value : TrafficLights.Red value : TrafficLights.Green value : TrafficLights.Yellow
- Related Articles
- Comments in Dart Programming
- Constructors in Dart Programming
- Functions in Dart Programming
- Immutability in Dart Programming
- Inheritance in Dart Programming
- Iterables in Dart Programming
- Lists in Dart Programming
- Loops in Dart Programming
- Maps in Dart Programming
- Methods in Dart Programming
- Mixins in Dart Programming
- Queue in Dart Programming
- Runes in Dart Programming
- Set in Dart Programming
- String in Dart Programming

Advertisements