using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Collections.ObjectModel; //csc List_BionarySearch1.cs namespace ConsoleApplication1 { class Program { static void Main(string[] args) { List eList = new List(); eList.Add("A"); eList.Add("B"); eList.Add("C"); eList.Add("D"); eList.Add("E"); readT(eList); IList e1 = eList.AsReadOnly(); Console.WriteLine("-printing- List eList-----"); int index = eList.BinarySearch("M"); if (index < 0) { eList.Insert(~index, "M"); } try { Console.WriteLine("erorr occurs"); e1[2] = "Z"; } catch { Console.WriteLine("-ReadOnly"); } foreach (string val in e1) { Console.WriteLine("IList Value:" + val.ToString()); } // readT(eList, " "); // Console.ReadLine(); } static void readT(IList list) { //notice that the list is passed an IList and hence can handle both types of lists //Use IEnumerable foreach (string val in list) { Console.WriteLine("IList Value:" + val.ToString()); } } } }