Tuesday, July 05, 2011

Enumerating different items from Arrays

This morning I started to working on some thing to compare the two array list or array values and identifying the similarities and differential items.
The below code is equivalent to looping the both arrays and identifying the common and different items in two array values.


In C#.NET 3.5 We have Intersect and Except extension method to get solution for these kind scenarios.
List List1 = new List();
List1.Add("Murugesan");
List1.Add("Geetha");
List1.Add("GuruSelvam");


List List2 = new List();
List2.Add("Murugesan");
List2.Add("Geetha");


List exce = List1.Except(List2).ToList();
foreach (string n in exce)
{
Response.Write(n.ToString());
}
//It will returns the GuruSelvam