0

I've recently learned about Arrays/2D Arrays and Lists/Dictionaries . I feel like using Lists/Dictionaries is so much more convenient and easy than Arrays/2D Arrays. What is the point of reversing an Array with so many lines of code, when you could use Lists and the .Reverse() function? It is also so much easier to access the information from a List. I never really experienced a situation where I would want to use an Array over a List. I might be completely wrong about my beginner opinion and that's why I am asking this question - to see if I'm right.

  • 1
    What do you mean by "double arrays"? Are you trying to describe 2D arrays? Otherwise, does this answer your question? [Array versus List: When to use which?](https://stackoverflow.com/questions/434761/array-versus-listt-when-to-use-which) – 41686d6564 stands w. Palestine Oct 01 '22 at 13:49
  • What are double arrays? A doubly-linked list? Two arrays of same size? – knittl Oct 01 '22 at 13:52
  • Note that although generic lists can generally be used as a substitute for one-dimensional arrays, dictionaries are not exactly a substitute for two-dimensional arrays. They have a totally different purpose. In addition to that a multi-dimensional array must have the same type for all dimensions, while a dictionary often has different types for the key vs value. – 41686d6564 stands w. Palestine Oct 01 '22 at 13:52
  • You do realise that there's an `Array.Reverse` method, right? You may well have had to use multiple lines of code to reverse an array as a learning exercise but no one does that in real code. – jmcilhinney Oct 01 '22 at 13:54
  • It's important to realise that arrays have to exist, because collections like `List` actually use them internally for storage. A `List` is a wrapper for an array that provides convenience in many common scenarios but there's still an array there and array operations taking place. Personally, I always use an array where an array will do the job and I use a collection where a collection adds value. If I need to add and remove items then obviously I'll use a collection but if I don't then I'd need some other reason to use a collection over an array. – jmcilhinney Oct 01 '22 at 13:58
  • When you use a collection type like List, Queue, Stack, Dictionary, HashSet (but not LinkedList) then you still use an array. It is just not visible, wrapped by the collection type. Arrays are fundamental to making collections fast on modern processors. You pay a bit extra for the additional functionality of the type, but the cost is low and rarely noticeable. So sure, feel free to use the more convenient collection type. Except LinkedList. – Hans Passant Oct 01 '22 at 14:04
  • My teacher calls them Double Arrays, but noted, I will call them 2D arrays from now on @41686d6564standsw.Palestine – Martin Slavchev Oct 01 '22 at 14:37
  • Depends on usage. Arrays are fixed size and so you use them when this is required. A list uses arrays internally, but can re-create them with a new size if needed. – John Alexiou Oct 01 '22 at 20:53

0 Answers0