In C#, SortedList is a collection of key/value pairs which are sorted according to keys. By default, this collection sort the key/value pairs in ascending order. It is of both generic and non-generic type of collection. The generic SortedList is defined in System.Collections.Generic namespace whereas non-generic SortedList is defined under System.Collections namespace.
1.01 and Bird 1.02 and Dog 1.04 and Rat 1.07 and Cat
In C#, SortedDictionary is a generic collection which is used to store the key/value pairs in the sorted form and the sorting is done on the key. SortedDictionary is defined under System.Collection.Generic namespace. It is dynamic in nature means the size of the sorted dictionary is growing according to the need.
Top 5 space agencies 2018: Rank: 1 and Name: NASA Rank: 2 and Name: CNSA Rank: 3 and Name: ESA Rank: 4 and Name: Roscosmos Rank: 5 and Name: ISRO
Below are the some differences between SortedList and SortedDictionary:
|The memory of SortedList is an overhead.||The memory of SortedDictionary is not bottlenecked.|
|In SortedList, the elements are stored in a continuous block in memory.||In SortedDictionary, the elements are stored in separate object that can spread all over the heap.|
|In SoterdList, the memory fragmentation is high.||In SoterdDictionary, the memory fragmentation is low.|
|It require less memory for storage.||It require more memory for storage.|
|In SortedList, less inserts and delete operations are required.||In SortedDictionary, more inserts and delete operations are required.|
|In SortedList, you can access elements using the index.||In SortedDictionary, you can access elements using index or key. Here key access is sufficient there is no need of accessing elements using index.|
|In SortedList, data are already in sorted form.||In SortedDictionary, data are in un-sorted form.|
- C# | Check if SortedDictionary contains the specified key or not
- SortedDictionary Class in C#
- SortedDictionary Implementation in C#
- C# | SortedDictionary.Add() Method
- C# | Get an enumerator that iterates through the SortedDictionary
- C# | SortedDictionary.Item Property
- C# | SortedDictionary.Values Property
- C# | SortedDictionary.ContainsValue() Method
- C# | SortedDictionary.Remove() Method
- C# | SortedDictionary.Keys Property
- C# | SortedDictionary.Count Property
- C# | SortedDictionary.Clear() Method
- Check if two SortedDictionary objects are equal in C#
- C# | Get or set the value associated with specified key in SortedList
- C# | How to create a SortedList
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.