Add element to SortedList by using the indexer. : SortedList : Data Structure C# Examples


C# Examples » Data Structure » SortedList »

 

Add element to SortedList by using the indexer.









    
using  System;  
using  System.Collections;  
  
class  MainClass  {  
    public  static  void  Main()  {  
        SortedList  sl  =  new  SortedList();  
          
        sl.Add("a",  "A");  
        sl.Add("b",  "B");  
        sl.Add("c",  "C");  
        sl.Add("d",  "D");  

        //  add  by  using  the  indexer.  
        sl["e"]  =  "E";  
  
        //  Get  a  collection  of  the  keys.  
        ICollection  c  =  sl.Keys;  
  
        //  Display  list  using  integer  indexes.  
        Console.WriteLine("Contents  by  integer  indexes.");  
        for(int  i=0;  i<sl.Count;  i++)  
            Console.WriteLine(sl.GetByIndex(i));  
            
    }
}
    
   
  
   



Output

Contents by integer indexes.
A
B
C
D
E


HTML code for linking to this page:

Follow Navioo On Twitter

C# Examples

 Navioo Data Structure
» SortedList