Difference between two list - CSharp System.Collections.Generic

CSharp examples for System.Collections.Generic:List

Description

Difference between two list

Demo Code


using System.Collections.Generic;
using System.Collections;
using System;/*  w  w  w.java  2s . c  o  m*/

public class Main{
        public static IList<T> DifferenceWith<T>(this IList<T> collection1, IList<T> collection2)
        {
            var difference = new List<T>();
            foreach (T item1 in collection1)
            {
                if (!collection2.Contains(item1))
                    difference.Add(item1);
            }

            return difference;
        }
}

Related Tutorials