C# SortedList Class Reference – Properties, Methods, Examples / Programs

SortedList class represents a collection (both generic and non-generic types of collections) of key/value pairs that are sorted by the keys and are accessible by key and by index.

To use SortedList class we need to use the following namespaces:

  • System.Collections.Generic
  • System.Collections

Now we will discuss some important points regarding SortedList:

  1. In SortedList, there are two arrays that will be maintained internally, one array is used to store keys and another array is used to maintain values.
  2. In SortedList, we cannot pass null for key, but we can pass the value as a null.
  3. Here, we can access SortedList items using a key or using the index.
  4. SortedList class implements the following interfaces:
    1. ICollection
    2. IEnumerable
    3. ICloneable
    4. IDictionary
  5. Duplicate keys are not allowed in SortedList.
  6. SortedList is used as a generic and non-generic type.
  7. We can cast key and value pair of SortedList into DictionaryEntry.

Creation of SortedList:

There are 6 different types of constructors are used in SortedList. Here, we need to include two namespaces System.Collections.Generic and System.Collections.

SortedList list = new SortedList();

This section contains the solved C# SortedList Class Reference – Properties, Methods, Examples. Practice these programs to learn the use of various SortedList-related methods/operations, these programs contain the solved code, outputs, and the detailed explanation of the statements, functions used in the C# SortedList Class Reference – Properties, Methods, Examples.

List of C# SortedList Class Reference – Properties, Methods, Examples

  1. C# - SortedList.Add() Method with Example
  2. C# - SortedList.Remove() Method with Example
  3. C# - SortedList.RemoveAt() Method with Example
  4. C# - SortedList.GetByIndex() Method with Example
  5. C# - SortedList.GetKey() Method with Example
  6. C# - SortedList.GetKeyList() Method with Example
  7. C# - SortedList.GetValueList() Method with Example
  8. C# - SortedList.IndexOfKey() Method with Example
  9. C# - SortedList.IndexOfValue() Method with Example
  10. C# - SortedList.ContainsKey() Method with Example
  11. C# - SortedList.ContainsValue() Method with Example
  12. C# - SortedList.Contains() Method with Example
  13. C# - SortedList.CopyTo() Method with Example
  14. C# - SortedList.Clone() Method with Example
  15. C# - SortedList.Clear() Method with Example
  16. C# - SortedList.Keys Property with Example
  17. C# - SortedList.Values Property with Example
  18. C# - SortedList.SetByIndex() Method with Example
  19. C# - SortedList.Capacity Property with Example

Comments and Discussions!

Load comments ↻

Copyright © 2024 www.includehelp.com. All rights reserved.