using System; using System.Collections; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Diagnostics; using System.Linq; //csc CollecT_Any_Distinct1.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(" dnames = names.Distinct(); "); IEnumerable names = from p in cTList where p.Any() select p; IEnumerable dnames = names.Distinct(); int n1 = 0; foreach (var v1 in dnames) { Console.WriteLine(v1 + " @\t " + 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++; } } } }