CSharp examples for System.Collections.Generic:IList
Add Range Distinct to IList
// 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 a va 2 s. c om*/ public class Main{ public static bool AddRangeDistinct<T>(this IList<T> list, IEnumerable<T> values, IEqualityComparer<T> comparer) { bool allAdded = true; foreach (T value in values) { if (!list.AddDistinct(value, comparer)) allAdded = false; } return allAdded; } public static bool AddRangeDistinct<T>(this IList<T> list, IEnumerable<T> values) { return list.AddRangeDistinct(values, EqualityComparer<T>.Default); } public static bool AddDistinct<T>(this IList<T> list, T value, IEqualityComparer<T> comparer) { if (list.ContainsValue(value, comparer)) return false; list.Add(value); return true; } public static bool AddDistinct<T>(this IList<T> list, T value) { return list.AddDistinct(value, EqualityComparer<T>.Default); } }