CSharp examples for System.Collections:ICollection
Add Unique value to ICollection
using System.Reflection; using System.Linq; using System.Collections.Generic; using System;/*from w w w . j a va 2 s .co m*/ public class Main{ public static void AddUnique<T>(this ICollection<T> items, T item) { if (!items.Contains(item)) { items.Add(item); } } public static bool Contains<T>(this IEnumerable<T> list, Func<T, bool> predicate) { foreach (var item in list) { if (predicate(item)) { return true; } } return false; } }