The following code contains some of the most common mistakes I have been seeing when reviewing code that deals with enumerable objects.
public static IEnumerable<T> ElementsFromTheFirstWhichAreAlsoInTheSecond<T>( IEnumerable<T> enumerable1, IEnumerable<T> enumerable2 ) { var result = new List<T>(); enumerable1.ToList().ForEach(a => { if (enumerable2.Contains(a)) { result.Add(a); } }); return result; }
Can you see what is wrong? Share in the comments.