using System; using System.Collections; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Diagnostics; using System.Linq; //csc CollecT_Except_ElementAt1.cs namespace ConsoleApplication1 { class Program { static void Main(string[] args) { Collection cTList = new Collection(); Collection cTList2 = new Collection(); cTList.Add("AD"); cTList.Add("B"); cTList.Add("AB"); cTList.Add("C"); cTList.Add("D"); cTList.Add("AD"); cTList.Add("E"); cTList.Add("AD"); Console.WriteLine("Reading List"); readT(cTList); cTList2.Add("AD"); Console.WriteLine("cTList.Except(cTList2).ToList()"); IEnumerable query1 = cTList.Except(cTList2).ToList(); int n1 = 0; foreach (var v1 in query1) { // Console.WriteLine(v1 + " @\t " + n1 + " "); Console.WriteLine("cTList.ElementAt(n1) " + cTList.ElementAt(n1) + " " +n1); n1++; } 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 int n1 = 0; foreach (string val in list) { Console.WriteLine(val + " @\t " + n1 + " "); n1++; } } } }