using System;
using System.Collections;
public class SamplesSortedList {
//csc string_IndexofValue.cs
public static void Main() {

// Creates and initializes a new SortedList.
SortedList playerlist = new SortedList();
playerlist.Add( 5, "Leon" );
playerlist.Add( 1, "Baba" );
playerlist.Add( 3, "Jacob" );
playerlist.Add( 2, "Dan" );
playerlist.Add( 4, "Peter" );
playerlist.Add( 0, "Kaleb" );

// Displays the values of the SortedList.
Console.WriteLine( "The SortedList contains the following values:" );
printindexofvalue( playerlist );

// Searches for a specific key.
int myKey = 2;
Console.WriteLine( "The key is at index "+ myKey +" "+ playerlist.IndexOfKey( myKey ) );
Console.Write("Enter Player Name : ");
// Searches for a specific value.
String player = Console.ReadLine();
Console.WriteLine( "The value \"{0}\" is at index {1}.", player, playerlist.IndexOfValue( player ) );
}


public static void printindexofvalue( SortedList myList ) {
Console.WriteLine( "\t-INDEX-\t-KEY-\t-NAME-" );
for ( int i = 0; i < myList.Count; i++ ) {
Console.WriteLine( "\t[{0}]:\t{1}\t{2}", i, myList.GetKey(i), myList.GetByIndex(i) );
}
Console.WriteLine();
}
}