Class CollectionExtensions
- Namespace
- NanoByte.Common.Collections
- Assembly
- NanoByte.Common.dll
Provides extension methods for System.Collections.Generic.ICollection<T>s.
public static class CollectionExtensions
- Inheritance
-
objectCollectionExtensions
Methods
AddIfNew<T>(ICollection<T>, T)
Adds an element to the collection if it does not already System.Collections.Generic.ICollection<T>.Contains(T) the element.
public static bool AddIfNew<T>(this ICollection<T> collection, T element)
Parameters
collection
ICollection<T>element
T
Returns
- bool
true
if the element was added to the collection;true
if the collection already contained the element.
Type Parameters
T
Remarks
This makes it possible to use a System.Collections.Generic.ICollection<T> with semantics similar to a System.Collections.Generic.HashSet<T>.
Add<TCollection, TElements>(ICollection<TCollection>, IEnumerable<TElements>)
Adds multiple elements to the collection.
public static void Add<TCollection, TElements>(this ICollection<TCollection> collection, IEnumerable<TElements> elements) where TElements : TCollection
Parameters
collection
ICollection<TCollection>elements
IEnumerable<TElements>
Type Parameters
TCollection
TElements
RemoveAll<T>(ICollection<T>, Func<T, bool>)
Removes all items from a collection
that match a specific condition
.
public static bool RemoveAll<T>(this ICollection<T> collection, Func<T, bool> condition)
Parameters
collection
ICollection<T>condition
Func<T, bool>
Returns
- bool
true
if any elements where removed.
Type Parameters
T
- See Also
-
RemoveAll(Predicate<T>)
Remove<TCollection, TElements>(ICollection<TCollection>, IEnumerable<TElements>)
Removes multiple elements from the collection.
public static bool Remove<TCollection, TElements>(this ICollection<TCollection> collection, IEnumerable<TElements> elements) where TElements : TCollection
Parameters
collection
ICollection<TCollection>elements
IEnumerable<TElements>
Returns
- bool
true
if any elements where removed.
Type Parameters
TCollection
TElements