using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.Linq; //csc List_First_LastIndex1.cs namespace ConsoleApplication1 { class Program { static void Main(string[] args) { List eList = new List(); eList.Add("AD"); eList.Add("B"); eList.Add("AB"); eList.Add("C"); eList.Add("D"); eList.Add("AD"); eList.Add("E"); eList.Add("AD"); // eList.Sort(); //Copies the entire List to a compatible one-dimensional array, //starting at the specified index of the target array String[] eList2 = new String[eList.Count()]; eList.CopyTo(eList2,0); Console.WriteLine("Reading List"); readT(eList); Console.WriteLine("Feeding string array : CopyTo"); foreach(string str in eList2) { Console.WriteLine(str); } int n1 = eList.FindIndex(s => s == "AD"); int n2 = eList.FindLastIndex(s => s == "AD"); Console.WriteLine("First Index "+ n1 + " LastIndex : " + n2); 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(val); } } } }