Created
          April 30, 2012 09:11 
        
      - 
      
- 
        Save AndrewBarfield/2556747 to your computer and use it in GitHub Desktop. 
    C#: System.Collections.Generic: Working with a Generic SortedList
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | using System; | |
| using System.Collections.Generic; | |
| using System.Linq; | |
| using System.Text; | |
| namespace GenericSortedList { | |
| class Program { | |
| static void Main(string[] args) { | |
| // Creates and initializes a new SortedList. | |
| SortedList<string, string> sortedList = new SortedList<string, string>(); | |
| // Adds values to the list | |
| sortedList.Add( "2", "b" ); | |
| sortedList.Add( "5", "e" ); | |
| sortedList.Add( "3", "c" ); | |
| sortedList.Add( "1", "a" ); | |
| sortedList.Add( "4", "d" ); | |
| // Displays the properties and values of the SortedList. | |
| Console.WriteLine( "Count: {0}", sortedList.Count ); | |
| Console.WriteLine( "Capacity: {0}", sortedList.Capacity ); | |
| Console.WriteLine( "Keys and Values:" ); | |
| // Displays keys and values | |
| for ( int i = 0 ; i < sortedList.Count ; i++ ) { | |
| Console.WriteLine( "{0}: {1}", sortedList.Keys[i], sortedList.Values[i] ); | |
| } | |
| // Allow user to read the Console | |
| Console.Read(); | |
| } | |
| } | |
| } | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment