One IList Minus another IList - CSharp System.Collections.Generic

CSharp examples for System.Collections.Generic:IList

Description

One IList Minus another IList

Demo Code

// Permission is hereby granted, free of charge, to any person
using System.Globalization;
using System.Linq;
using System.Collections;
using System.Text;
using System.Reflection;
using System.Collections.ObjectModel;
using System.Collections.Generic;
using System;/*from  w w  w .j  av a2 s  .c  om*/

public class Main{
        #endregion

    public static IList<T> Minus<T>(IList<T> list, IList<T> minus)
    {
      ValidationUtils.ArgumentNotNull(list, "list");

      List<T> result = new List<T>(list.Count);
      foreach (T t in list)
      {
        if (minus == null || !minus.Contains(t))
          result.Add(t);
      }

      return result;
    }
}

Related Tutorials