How to use SortedList in C#

1 Answer

0 votes
using System;
using System.Collections.Generic;
  
class Program
{
    static void Main() {
        SortedList<string, int> sl = new SortedList<string, int>();
         
        sl.Add("c#", 30);
        sl.Add("java", 20);
        sl.Add("python", 50);
        sl.Add("c", 10);
        sl.Add("c++",40);


        foreach (KeyValuePair<string, int> item in sl)
            Console.WriteLine($"{item.Key} : {item.Value}");
    }
}
 
  
  
/*
run:
  
c : 10
c# : 30
c++ : 40
java : 20
python : 50

*/

 



answered Dec 13, 2020 by avibootz

Related questions

2 answers 223 views
2 answers 258 views
1 answer 191 views
...