SortedList in Visual Basic .NET
Last Updated: March 19, 2020
SortedList collection in VB.NET stored the key-value pairs collections which are sorted by the key
This is a simple code written in VB.NET to show how SortedList work. I have added the days of the week to the SortedList in random way.
Module Module1 Sub Main() Dim slist As New SortedList slist.Add("2", "Monday") slist.Add("1", "Sunday") slist.Add("7", "Saturday") slist.Add("5", "Thursday") slist.Add("4", "Wednesday") slist.Add("6", "Friday") slist.Add("3", "Tuesday") For Each element As DictionaryEntry In slist Console.WriteLine("key = " + element.Key + " Value = " + element.Value) Next Console.ReadLine() End Sub End Module
Output
key = 1 Value = Sunday key = 2 Value = Monday key = 3 Value = Tuesday key = 4 Value = Wednesday key = 5 Value = Thursday key = 6 Value = Friday key = 7 Value = Saturday
When you look at the output of the iteration you can see that key has been sorted