C# SortedList Class 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 Programs. 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 Programs.

List of C# SortedList Class Programs

  1. C# program to add elements into a SortedList (Example of Add() Method)
  2. C# program to remove an element from a SortedList (Example of Remove() Method)
  3. C# program to remove an element at the specified index from a SortedList (Example of RemoveAt() Method)
  4. C# program to get the value at the specified index from a SortedList (Example of GetByIndex() Method)
  5. C# program to get the key at the specified index of a SortedList (Example of GetKey() Method)
  6. C# program to get the keys in a SortedList (Example of GetKeyList() Method)
  7. C# program to get the values in a SortedList (Example of GetValueList() Method)
  8. C# program to get the index of the specified key in a SortedList (Example of IndexOfKey() Method)
  9. C# program to get the index of the first occurrence of the specified value in a SortedList (Example of IndexOfValue() Method)
  10. C# program to check whether a SortedList object contains a specific key (Example of ContainsKey() Method)
  11. C# program to check whether a SortedList object contains a specific value (Example of ContainsValue() Method)
  12. C# program to check whether a SortedList object contains a specific key (Example of Contains() Method)
  13. C# program to get the keys in a SortedList object (Example of Keys Property)
  14. C# program to get the values in a SortedList object (Example of Values Property)
  15. C# program to replace the value at a specific index in a SortedList object (Example of SetByIndex() Method)
  16. C# program to copy SortedList elements to a one-dimensional Array object (Example of CopyTo() Method)
  17. C# program to create a shallow copy of a SortedList object (Example of Clone() Method)
  18. C# program to remove all elements from a SortedList object (SortedList.Clear() Method)
  19. C# program to get or set the capacity of a SortedList object (SortedList.Capacity Property)




Comments and Discussions




Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.