Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
Array is just a sequential memory location, that stores elements of the same type.
A collection is a datastructure that abstracts the process of managing elements (calculating indices, resizing arrays, iterators, map-reduce, ...), And generalizes it with interfaces, so you can change the storage backend later on (eg. From ArrayList to LinkedList). -
Bubbles66125y@metamourge oh I see. And this is coming from someone who’s honestly still relatively new to C#’s concepts but does LINQ have to do with Collections?
-
@Bubbles
I'm not a C#-dev, but from what I know, LINQ can be applied to process elements of DS, that implement a certain interface. -
-
Gxost3015yArrays have fixed size and don't give you methods for adding/removing items. Collections have more features and solve their specific tasks. List manages its own array inside and allows to add/insert/remove items and implements sorting. HashSet stores unique items and allows quickly check if an item is in collection. Dictionary stores (key, value) pairs. Every time you need a collection to store items you should choose the best option for your requirements
-
@Gxost Thanks for replying what I wanted to reply.
foreach loops only work with IEnumerables, too, so that's an indicator. -
SomeNone7115yArrays are for when you have a fixed amount of data, quantity known in advance, and not changing throughout the lifetime of the array. If that is not the case, use a List<T> or something else.
LINQ is for performing queries and operations over any collection that implements IEnumerable<T> and/or IQueryable<T>. This will apply to almost all .NET collection types. -
Arrays for fixed size data or for low level stuff (implementing your own data structures)
Collections for general use
Related Rants
In C# should I be using collections over normal arrays?
What’s the difference and what are the benefits of using collections?
question
arrays
c#
collections