Wilsonhut
Deal with it or don't
Monthly Archives: August 2012
Obvious Extension Methods: The Simple Join
August 22, 2012
Posted by on Maybe you just want to know the things from list1 where they have a match in list2.
You can do that yesterday and today with list1.Join(list2, item1=>item1, item2=>item2, (item1,item2)=>item1);
But today and tomorrow, you can simply do list1.Join(list2).
Obvious, right?
- public static class Extensions
- {
- public static IEnumerable<T> Join<T>(this IEnumerable<T> outer,
- IEnumerable<T> inner)
- {
- return outer.Join(inner, a => a, b => b, (a, b) => a);
- }
- }