CollectionExtensions Class
Click or drag to resize

CollectionExtensions Class

Extensions methods to ease dealing with collections.
Inheritance Hierarchy
SystemObject
  TomsToolbox.CoreCollectionExtensions

Namespace:  TomsToolbox.Core
Assembly:  TomsToolbox.Core (in TomsToolbox.Core.dll) Version: 1.0.72.0
Syntax
public static class CollectionExtensions

The CollectionExtensions type exposes the following members.

Methods
  NameDescription
Public methodStatic memberAddRange(IList, IEnumerable)
Adds the elements of the specified collection to the end of the list.
Public methodStatic memberAddRangeT(ICollectionT, IEnumerableT)
Adds the elements of the specified collection to the end of the list.
Public methodStatic memberAddRangeT(ICollectionT, T, T, T)
Adds the elements of the specified collection to the end of the list.
Public methodStatic memberContainsAny(String, Char)
Shortcut to test if any of the given characters is contained in the specified string.
Public methodStatic memberContainsAnyT(IEnumerableT, T)
Shortcut to test if any of the given items are contained in the specified object.
Public methodStatic memberContainsAnyT(IEnumerableT, IEqualityComparerT, T)
Shortcut to test if any of the given items are contained in the specified object.
Public methodStatic memberFindIndexT
Searches for an element that matches the conditions defined by the specified predicate, and returns the zero-based index of the first occurrence within the entire IEnumerableT.
Public methodStatic memberForceValueTKey, TValue(IDictionaryTKey, TValue, TKey, FuncTKey, TValue)
Gets the value associated with the specified key from the dictionary, or creates a new entry if the dictionary does not contain a value associated with the key.

[CanBeNull]

Public methodStatic memberForceValueTKey, TValue(IDictionaryTKey, TValue, TKey, TValue)
Gets the value associated with the specified key from the dictionary, or creates a new entry if the dictionary does not contain a value associated with the key.

[CanBeNull]

Public methodStatic memberForEachT(IEnumerableT, ActionT)
Performs the specified action on each element of the collection.
Public methodStatic memberForEachT(IEnumerableT, ActionT, Int32)
Performs the specified action on each element of the collection, providing also the index of the item.
Public methodStatic memberGetValueOrDefaultTKey, TValue(IDictionaryTKey, TValue, TKey)
Gets the value from the dictionary, or the default value of TValue if no item with the specified key exists.

[CanBeNull]

Public methodStatic memberGetValueOrDefaultTKey, TValue(IDictionaryTKey, TValue, TKey, TValue)
Gets the value from the dictionary, or the default value if no item with the specified key exists.

[CanBeNull]

Public methodStatic memberIndexOfT(IEnumerableT, T)
Searches for the specified object and returns the zero-based index of the first occurrence within all items.
Public methodStatic memberIndexOfT(IEnumerableT, T, IEqualityComparerT)
Searches for the specified object and returns the zero-based index of the first occurrence within all items.
Public methodStatic memberRemoveRange(IList, IEnumerable)
Removes a range of elements from the list.
Public methodStatic memberRemoveRangeT(ICollectionT, IEnumerableT)
Removes a range of elements from the list.
Public methodStatic memberRemoveRangeT(ICollectionT, FuncT, Boolean)
Removes the range of elements from the list that fulfill the condition.
Public methodStatic memberRepeatT
Repeats the specified source multiple times.

[ItemCanBeNull, NotNull]

Public methodStatic memberSynchronizeWithT(ICollectionT, ICollectionT)
Synchronizes the items of the source list with the items of the target list. The order of the items is ignored.
Public methodStatic memberSynchronizeWithT(ICollectionT, ICollectionT, IEqualityComparerT)
Synchronizes the items of the source list with the items of the target list. The order of the items is ignored.
Public methodStatic memberTakeT
Retrieves the specified number of items from the source. If source contains less items than specified, all available items are returned.

[NotNull, ItemCanBeNull]

Public methodStatic memberToArrayTSource, TTarget
Creates an array from a ICollectionT. This method is faster than using Enumerable.Select(selector).ToArray() because the size of the target array is known in advance.

[NotNull, ItemCanBeNull]

Public methodStatic memberToDictionaryTKey, TValue(IEnumerableKeyValuePairTKey, TValue)
Creates a Dictionary{TKey, TValue} from an IEnumerable{KeyValuePair{TKey, TValue}}.

[NotNull]

Public methodStatic memberToDictionaryTKey, TValue(IEnumerableKeyValuePairTKey, TValue, IEqualityComparerTKey)
Creates a Dictionary{TKey, TValue} from an IEnumerable{KeyValuePair{TKey, TValue}}.

[NotNull]

Public methodStatic memberTransposeTKey, TValue
Transposes the specified items, i.e. exchanges key and value.

[NotNull]

Public methodStatic memberTryAddRangeT
Adds the elements of the specified collection to the end of the list, but ignores all ArgumentException, e.g. when trying to add duplicate keys to a dictionary.
Top
See Also