using System; using System.Collections; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Diagnostics; using System.Linq; //csc CollecT_Contains1.cs namespace ConsoleApplication1 { class Program { static void Main(string[] args) { Collection cTList = 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"); IEnumerable query1 = cTList.Where(e => e.Contains("AD")); Console.WriteLine("Reading List"); readT(cTList); // Console.WriteLine(" from p in cTList where p.Any()"); //IEnumerable names = from p in cTList where p.Any() select p; Console.WriteLine("cTList.Where(e => e.Contains"+"('AD')"); int n1 = 0; foreach (var v1 in query1) { if (v1 == "AD") { Console.WriteLine(v1 + " @ " + n1 + " "); } else { Console.WriteLine(v1 + " @ " + n1 + " "); }// wont'print 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 foreach (string val in list) { Console.WriteLine(val); } } } }