In table below official recommendations for choosing data structure for your needs:
Generic | Non-Generic | Thread safe | Purpose |
Dictionary | Hashtable | ConcurrentDictionary | key value pairs, lookup |
List | Array | ImmutableList | access items by index |
Queue | – | ConcurrentQueue | FIFO queue |
Stack | – | ConcurrentStack | LIFO queue |
LinkedList | – | – | access items sequentially |
ObservableCollection | – | – | notfications after modification |
SortedList | ImmutableSortedSet | auto sorted collection | |
HashSet | ImmutableHashSet | dictionary of just keys (high performance set operations) |
Further read:
https://learn.microsoft.com/en-us/dotnet/standard/collections/
One Reply to “Data structures in .NET”