{"id":3586,"date":"2022-05-19T06:06:01","date_gmt":"2022-05-19T06:06:01","guid":{"rendered":"https:\/\/mdr.foobrdigital.com\/?p=3586"},"modified":"2022-05-19T06:06:01","modified_gmt":"2022-05-19T06:06:01","slug":"dart-enumeratio","status":"publish","type":"post","link":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/2022\/05\/19\/dart-enumeratio\/","title":{"rendered":"Dart Enumeratio"},"content":{"rendered":"\n<p>An enumeration is a set of values called as elements, members, etc. This is essential when we carried out the operation with the limited set of values available for variable. For example &#8211; you can think of the days of the month can only be one of the seven days &#8211; Sun, Mon, Tue, Wed, Thur, Fri, Sat.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Initializing an Enumeration<\/h2>\n\n\n\n<p>The enumeration is declared using the&nbsp;<strong>enum<\/strong>&nbsp;keyword, followed by the comma-separated list of the valid identifiers. This list is enclosed within the curly braces {}. The syntax is given below.<\/p>\n\n\n\n<p><strong>Syntax &#8211;<\/strong><a href=\"https:\/\/www.javatpoint.com\/dart-enumeration#\"><\/a><a href=\"https:\/\/www.javatpoint.com\/dart-enumeration#\"><\/a><a href=\"https:\/\/www.javatpoint.com\/dart-enumeration#\"><\/a><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>enum &lt;enum_name> {  \nconst1,   \nconst2,   \n....., constN  \n}  <\/code><\/pre>\n\n\n\n<p>Here, the enum_name denotes the enum type name and list of the identifiers enclosed within the curly bracket.<\/p>\n\n\n\n<p>Each of the identifier in the enumeration list has its index position. The index of the first enumeration is 0; the second enumeration is 1, and so on.<\/p>\n\n\n\n<p><strong>Example &#8211;<\/strong><\/p>\n\n\n\n<p>Let&#8217;s define an enumeration for months of the year.<a href=\"https:\/\/www.javatpoint.com\/dart-enumeration#\"><\/a><a href=\"https:\/\/www.javatpoint.com\/dart-enumeration#\"><\/a><a href=\"https:\/\/www.javatpoint.com\/dart-enumeration#\"><\/a><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>enum EnumofYear {   \nJanuary,  \nFebruary,  \nMarch,  \nApril,  \nMay,  \nJune,  \nJuly,  \nAugust,  \nSeptember,  \nOctober,  \nNovember,  \nDecember,  \n}  <\/code><\/pre>\n\n\n\n<p>Let&#8217;s say programming example &#8211;<\/p>\n\n\n\n<p><strong>Example &#8211;<\/strong><a href=\"https:\/\/www.javatpoint.com\/dart-enumeration#\"><\/a><a href=\"https:\/\/www.javatpoint.com\/dart-enumeration#\"><\/a><a href=\"https:\/\/www.javatpoint.com\/dart-enumeration#\"><\/a><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>enum EnumofYear {   \nJanuary,  \nFebruary,  \nMarch,  \nApril,  \nMay,  \nJune,  \nJuly,  \nAugust,  \nSeptember,  \nOctober,  \nNovember,  \nDecember,  \n}  \nvoid main() {  \n   print(\"Javapoint - Dart Enumeration\" );  \n   print(EnumofYear.values);  \n   EnumofWeek.values.forEach((v) => print('value: $v, index: ${v.index}'));   \n}  <\/code><\/pre>\n\n\n\n<p><strong>Output:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Javapoint - Dart Enumeration\n&#91;EnumofYear.January, EnumofYear.February, EnumofYear.March, EnumofYear.April, EnumofYear.May, EnumofYear.June, EnumofYear.July, EnumofYear.August, EnumofYear.September, EnumofYear.October, EnumofYear.November, EnumofYear.December]\nvalue: EnumofYear.January, index: 0\nvalue: EnumofYear.February, index: 1\nvalue: EnumofYear.March, index: 2\nvalue: EnumofYear.April, index: 3\nvalue: EnumofYear.May, index: 4\nvalue: EnumofYear.June, index: 5\nvalue: EnumofYear.July, index: 6\nvalue: EnumofYear.August, index: 7\nvalue: EnumofYear.September, index: 8\nvalue: EnumofYear.October, index: 9\nvalue: EnumofYear.November, index: 10\nvalue: EnumofYear.December, index: 11\n<\/code><\/pre>\n\n\n\n<p><strong>Example &#8211; 2<\/strong><\/p>\n\n\n\n<p><a href=\"https:\/\/www.javatpoint.com\/dart-enumeration#\"><\/a><a href=\"https:\/\/www.javatpoint.com\/dart-enumeration#\"><\/a><a href=\"https:\/\/www.javatpoint.com\/dart-enumeration#\"><\/a><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>enum Process_Status {   \n   none,   \n   running,   \n   stopped,   \n   paused   \n}    \nvoid main() {   \n   print(Process_Status.values);   \n   Process_Status.values.forEach((v) => print('value: $v, index: ${v.index}'));  \n   print('running: ${Process_Status.running}, ${Process_Status.running.index}');   \n   print('running index: ${Process_Status.values&#91;1]}');   \n}  <\/code><\/pre>\n\n\n\n<p><strong>Output:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&#91;Process_Status.none, Process_Status.running, Process_Status.stopped, Process_Status.paused]\nvalue: Process_Status.none, index: 0\nvalue: Process_Status.running, index: 1\nvalue: Process_Status.stopped, index: 2\nvalue: Process_Status.paused, index: 3\nrunning: Process_Status.running, 1\nrunning index: Process_Status.running<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>An enumeration is a set of values called as elements, members, etc. This is essential when we carried out the operation with the limited set of values available for variable. For example &#8211; you can think of the days of the month can only be one of the seven days &#8211; Sun, Mon, Tue, Wed, [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[917],"tags":[],"_links":{"self":[{"href":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/wp-json\/wp\/v2\/posts\/3586"}],"collection":[{"href":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/wp-json\/wp\/v2\/comments?post=3586"}],"version-history":[{"count":0,"href":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/wp-json\/wp\/v2\/posts\/3586\/revisions"}],"wp:attachment":[{"href":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/wp-json\/wp\/v2\/media?parent=3586"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/wp-json\/wp\/v2\/categories?post=3586"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/wp-json\/wp\/v2\/tags?post=3586"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}