0

I'm learning about enumerations and I'm trying to understand what is the difference between enumerations and arrays. I've been googling online but haven't quite found any solid answers for this question that's been boggling me.

They both seem quite similar in the sense that they are both lists from which I can retrieve data. I understand that enumerations are constants so their values cannot be changed (correct me if my technical explanation is erroneous - just started learning coding). Under what situations do I use arrays instead of enumerations and vice versa?

Note: I'm asking about enumerations, not IEnumerables.

Updated: In the comments section, it was suggested that this link: Enumeration versus array was similar to my question. Indeed, the question is similar but I realised the arguments pertaining to the difference between enumerations and arrays could be debunked for example:

1) Enumerations cannot be printed at runtime - but I tried the "GetNames" method, e.g:

Enum.GetNames(typeof(enum name))

and it was able to display the string name of the member in the Enum.

2) Enumerations start from 0 - but I can do this:

public enum Days { Monday = 1, Tuesday, Wednesday}

which can change the index of enums and push up all the indexes of the other members by 1 as well.

So I'm still a bit confused. Enums and arrays seem quite similar, maybe not in the way they are constructed, but the way they are used to extract values possibly? (correct me if i'm wrong once again)

Update again: I understand now. Enums can't store data, while arrays can. Also, this link is pretty good: What is main use of Enumeration?

Community
  • 1
  • 1
Quenta221
  • 21
  • 4
  • If you mean IEnumerables: It is sort of popular question. There are many answers on SO: http://stackoverflow.com/questions/764748/whats-the-difference-between-ienumerable-and-array-ilist-and-list, http://stackoverflow.com/questions/3577329/what-is-the-difference-between-ienumerable-and-arrays and many others. – Yeldar Kurmangaliyev Mar 03 '17 at 03:35
  • Enumerations and IEnumerables are the same? – Quenta221 Mar 03 '17 at 03:35
  • No, they're different. `enum` != `IEnumerable` in this case. Since C# `enum` behavior is similar with C++, look at this: http://stackoverflow.com/questions/13866683/enumeration-versus-array. – Tetsuya Yamamoto Mar 03 '17 at 03:37
  • My bad. I supposed that you mean IEnumerables. If you talk about `enum`, then I see nothing common between them. Difference is everything - how you declare them, how and why you use them :) Arrays are data structures, they store data. Enums do not store data, it is just a set of named integer constants. – Yeldar Kurmangaliyev Mar 03 '17 at 03:37
  • Thanks! I get it fully now :D – Quenta221 Mar 03 '17 at 04:30

0 Answers0