using System; using System.Collections; using System.Collections.ObjectModel; using System.Collections.Generic; using System.Diagnostics; using System.Linq; //csc CollecT_Any1.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"); 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; int n1 = 0; foreach (var v1 in names) { if (v1=="AD") { Console.WriteLine( v1 + " @ " + n1 + " ");} else { Console.WriteLine(v1 + " @ " + n1 + " "); } n1++; } Console.ReadLine(); } static void readT(Collection 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("index " + n1 + " string " + val); n1++; } } } }