The following code demonstrates how to get the common elements in
given 2 lists using Intersect method of System.Collections.Generic.List.
using System;
using System.Linq;
namespace ConsoleApplication1
{
static class Program
{
static void Main(string[] args)
{
int[] elementSet1 = { 5, 1, 6, 3, 8 };
int[] elementSet2 = { 3, 7, 8, 6, 5 };
foreach (int element in elementSet1.Intersect(
elementSet2))
{
Console.WriteLine(element);
}
Console.Read();
}
}
}
Showing posts with label intersect. Show all posts
Showing posts with label intersect. Show all posts
Tuesday, September 22, 2009
Find common elements in c# generic list
Labels:
c# generic list,
common elements,
Dot Net 3.5,
intersect,
LINQ
Subscribe to:
Posts (Atom)