using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class UsingSortedList : System.Web.UI.Page
{
   protected void Page_Load(object sender, EventArgs e)
   {
      // create sample customer objects
      Customer c1 = new Customer("334", "Thomas", "Hobbes", "123-4567");
      Customer c2 = new Customer("123", "Jean-Jacques", "Rosseau", "456-1267");
      Customer c3 = new Customer("085", "David", "Hume", "564-7823");
      Customer c4 = new Customer("254", "Martin", "Heidegger", "253-6383");

      // create and populate collection
      SortedList mySort = new SortedList();
      mySort.Add(c1.Id, c1);
      mySort.Add(c2.Id, c2);
      mySort.Add(c3.Id, c3);
      mySort.Add(c4.Id, c4);

      // iterate through the collection
      foreach (Customer c in mySort.Values)
      {
         labMsg.Text += c.Id + "," + c.LastName + "<br/>";
      }
      labMsg.Text += "<hr/>";

      Customer tempCust1 = (Customer)mySort["123"];
      labMsg.Text += tempCust1.Id + "," + tempCust1.LastName + "<br/>";
      Customer tempCust2 = (Customer)mySort.GetByIndex(3);
      labMsg.Text += tempCust2.Id + "," + tempCust2.LastName + "<br/>";

   }
}
