Skip to content

Instantly share code, notes, and snippets.

@AndrewBarfield
Created April 30, 2012 09:11
Show Gist options
  • Save AndrewBarfield/2556747 to your computer and use it in GitHub Desktop.
Save AndrewBarfield/2556747 to your computer and use it in GitHub Desktop.
C#: System.Collections.Generic: Working with a Generic SortedList
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