codeSMART

Generic List ContainsOneOf

Posted by: daggmano on: July 14, 2008

I needed a function that would return a boolean indicating if any of the values from one list appeared in another list.  I love extension methods…


public static bool ContainsOneOf<T>(this IList<T> first, IList<T> second)
{
    foreach (T item in first)
    {
        if (second.Contains(item))
            return true;
    }
    return false;
}

Remember to place this method in a public static class.

Leave a Reply

del.icio.us

Pages

 

July 2008
S M T W T F S
« Jun   Aug »
 12345
6789101112
13141516171819
20212223242526
2728293031