Add Range If Not In List - CSharp System.Collections.Generic

CSharp examples for System.Collections.Generic:IList

Description

Add Range If Not In List

Demo Code

/********************************************************************
 *  FulcrumWeb RAD Framework - Fulcrum of your business             *
 *  Copyright (c) 2002-2010 FulcrumWeb, ALL RIGHTS RESERVED         *
 *                                                                  *
 *  THE SOURCE CODE CONTAINED WITHIN THIS FILE AND ALL RELATED      *
 *  FILES OR ANY PORTION OF ITS CONTENTS SHALL AT NO TIME BE        *
 *  COPIED, TRANSFERRED, SOLD, DISTRIBUTED, OR OTHERWISE MADE       *
 *  AVAILABLE TO OTHER INDIVIDUALS WITHOUT EXPRESS WRITTEN CONSENT  *
 *  AND PERMISSION FROM FULCRUMWEB. CONSULT THE END USER LICENSE    *
 *  AGREEMENT FOR INFORMATION ON ADDITIONAL RESTRICTIONS.           *
 ********************************************************************/
using System.Collections.Specialized;
using System.Collections.Generic;
using System.Collections;
using System;//w  w  w .  ja  va 2s .  co m

public class Main{
        //--------------------------------------------------------------------------
    static public void AddRangeIfNotInList<T>(IList<T> list, IList<T> appendix, Func<IList<T>, T, bool> containsFunc = null)
    {
      if (containsFunc == null)
        containsFunc = (l, i) => l.Contains(i);
      foreach (var item in appendix)
      {
        if (!containsFunc(list, item))
          list.Add(item);
      }
    }
}

Related Tutorials