简体   繁体   中英

Difference between an Enum and a List in Dart

I read that enums are used for defining named constant values. But I dont get how it is different from a list in dart. Anyone cares to explain?

An enum is used for defining named constants values. Constant values in the sense that once it is defined, it cannot be added to, removed or changed just as a const variable.

While a List on the other hand, is used to store objects too. Which can be manipulated such as add, remove and change the values in the list. Which is not allowed on enum.

Enum is a user-defined data type. The built-in enum in dart stores an index, and a name with a string value.

Lists, on the other hand, can store objects. You can also add, remove and change values in lists, however, this is not allowed on enum.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM