Use SortedList Class - CSharp Collection

CSharp examples for Collection:SortedList

Description

Use SortedList Class

Demo Code

using System;/*w  w  w .java 2 s. c o  m*/
using System.Collections;
class Program {
   static void Main(string[] args) {
      SortedList sl = new SortedList();
      sl.Add("001", "A");
      sl.Add("002", "B");
      sl.Add("003", "C");
      sl.Add("004", "D");
      sl.Add("005", "E");
      sl.Add("006", "F");
      sl.Add("007", "G");
      if (sl.ContainsValue("N")) {
         Console.WriteLine("This student name is already in the list");
      } else {
         sl.Add("008", "N");
      }
      ICollection key = sl.Keys;
      foreach (string k in key) {
         Console.WriteLine(k + ": " + sl[k]);
      }
   }
}

Result


Related Tutorials