Course Content

Course Content

FAQs

SortedList in C# is a collection of key/value pairs that are sorted by keys. This collection sorts the key/value pairs in ascending order by default.

The benefits of using a sorted list include:

  • It helps you to organize your thoughts, ideas, and content in an easier way
  • It helps you to find what you need in a more efficient way
  • You can use it as a starting point for other types of lists, such as top 10 lists

Sorted list is widely used in C sharp programming language. It has many use cases like displaying the items of the list, iterating through the items of the list, displaying an item before or after another item, etc.

A key or index can be used to access an entry in a SortedList. Internally, a SortedList object maintains two arrays to contain the list's elements: one for the keys and another for the associated values. A key cannot be null in this case, but a value can.

To create a sorted list in C sharp, use the Sort method as follows:

Array.Sort(items, Compare);

  • The Compare function will compare two values and return an integer value between 0 and 1 that represents how closely they are to each other in value. The first value will be considered to be less than the second if their difference is less than 0, otherwise, it will be considered to be greater than the second if their difference is greater than 0 (1 means equal).

Recommended Courses

Share With Friend

Have a friend to whom you would want to share this course?

Download LearnVern App

App Preview Image
App QR Code Image
Code Scan or Download the app
Google Play Store
Apple App Store
598K+ Downloads
App Download Section Circle 1
4.57 Avg. Ratings
App Download Section Circle 2
15K+ Reviews
App Download Section Circle 3
  • Learn anywhere on the go
  • Get regular updates about your enrolled or new courses
  • Share content with your friends
  • Evaluate your progress through practice tests
  • No internet connection needed
  • Enroll for the webinar and join at the time of the webinar from anywhere