Skip to content

Instantly share code, notes, and snippets.

@kevinblumenfeld
Last active December 19, 2023 14:59
Show Gist options
  • Star 60 You must be signed in to star a gist
  • Fork 20 You must be signed in to fork a gist
  • Save kevinblumenfeld/4a698dbc90272a336ed9367b11d91f1c to your computer and use it in GitHub Desktop.
Save kevinblumenfeld/4a698dbc90272a336ed9367b11d91f1c to your computer and use it in GitHub Desktop.

Credit: Mark Kraus
Website: https://get-powershellblog.blogspot.com

Collection Type Guidence

When to use what

  • Use Arrays if you know the element types and have a fixed length and/or known-up-front collection size that will not change.
  • Use ArrayList if you have an unkown collection size with either unknown or mixed type elements.
  • Use a Generic List when know the type of the elements but not the size of the collection.
  • Use a HashTable if you are going to do key based lookups on a collection and don't know the object type of the elements.
  • Use a Dictionary<TKey, TValue> you are going to do key based lookups on a collection and you know the type of the elements.
  • Use a HashSet when you know the type of elements and just want unique values and quick lookups and assignmnets.
  • Use LinkList if you are going to make large numbers of additions and subtractions to an ordered list (and have the understanding to use this type)
  • Use Queue if you will build a collection that will need to be worked on First-in-first-out FIFO
  • Use Stack if you will build a collection that will need to be worked Last-in-first-out LIFO
  • Use SortedSet when you need a HasSet like set, but sorted (alaphbetically, for example)
  • Use SortedList when you need a List, but sorted (alaphbetically, for example)
  • Use SortedDictionary<TKey, TValue> when you need a Dictionary<TKey, TValue>, but sorted (alaphbetically, for example)

Avoid the following:

@MatanatAdigozelova
Copy link

In c# sortlist this fifo or lifo?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment