Show / Hide Table of Contents

Class CollectionExtensions

Provides extension methods for ICollection<T>s.

Inheritance
Object
CollectionExtensions
Namespace: NanoByte.Common.Collections
Assembly: NanoByte.Common.dll
Syntax
public static class CollectionExtensions : Object

Methods

AddIfNew<T>(ICollection<T>, T)

Adds an element to the collection if it does not already Contains(T) the element.

Declaration
public static bool AddIfNew<T>(this ICollection<T> collection, T element)
Parameters
Type Name Description
ICollection<T> collection
T element
Returns
Type Description
Boolean

true if the element was added to the collection; true if the collection already contained the element.

Type Parameters
Name Description
T
Remarks

This makes it possible to use a ICollection<T> with semantics similar to a HashSet<T>.

AddRange<TCollection, TElements>(ICollection<TCollection>, IEnumerable<TElements>)

Adds multiple elements to the collection.

Declaration
public static void AddRange<TCollection, TElements>(this ICollection<TCollection> collection, IEnumerable<TElements> elements)
    where TElements : TCollection
Parameters
Type Name Description
ICollection<TCollection> collection
IEnumerable<TElements> elements
Type Parameters
Name Description
TCollection
TElements
See Also
AddRange(IEnumerable<T>)

RemoveAll<T>(ICollection<T>, Func<T, Boolean>)

Removes all items from a collection that match a specific condition.

Declaration
public static bool RemoveAll<T>(this ICollection<T> collection, Func<T, bool> condition)
Parameters
Type Name Description
ICollection<T> collection
Func<T, Boolean> condition
Returns
Type Description
Boolean

true if any elements where removed.

Type Parameters
Name Description
T
See Also
RemoveAll(Predicate<T>)

RemoveRange<TCollection, TElements>(ICollection<TCollection>, IEnumerable<TElements>)

Removes multiple elements from the collection.

Declaration
public static void RemoveRange<TCollection, TElements>(this ICollection<TCollection> collection, IEnumerable<TElements> elements)
    where TElements : TCollection
Parameters
Type Name Description
ICollection<TCollection> collection
IEnumerable<TElements> elements
Type Parameters
Name Description
TCollection
TElements
See Also
RemoveRange(Int32, Int32)
In This Article
Back to top Copyright Bastian Eicher