简体   繁体   English

Dart 中枚举和列表的区别

[英]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.但我不明白它与 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.常量值一旦被定义,就不能像 const 变量一样添加、删除或更改。

While a List on the other hand, is used to store objects too.另一方面,List 也用于存储对象。 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. dart 中的内置枚举存储一个索引和一个带有字符串值的名称。

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.您还可以添加、删除和更改列表中的值,但是,这在枚举上是不允许的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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