Early Preview
This is currently very much a preview. Please feel free to try things out,
but don't be upset if anything is not yet working. Feedback is welcome over on our
GitHub Dicussions page.
class System.​Collections.​Generic.​CollectionExtensions
Assembly: System.Collections
Inheritance: object → CollectionExtensions
Provides extension methods for generic collections.
Methods
public static
void
AddRange​(List<​T> list,
ReadOnlySpan<​T> source)
Adds the elements of the specified span to the end of the <see cref="T:System.Collections.Generic.List`1" /> .
list
The list to which the elements should be added.
source
The span whose elements should be added to the end of the <see cref="T:System.Collections.Generic.List`1" /> .
public static
void
CopyTo​(List<​T> list,
Span<​T> destination)
Copies the entire <see cref="T:System.Collections.Generic.List`1" /> to a span.
list
The list from which the elements are copied.
destination
The span that is the destination of the elements copied from <paramref name="list" /> .
public static
TValue
GetValueOrDefault​(IReadOnlyDictionary<​TKey, TValue> dictionary,
TKey key)
Tries to get the value associated with the specified <paramref name="key" /> in the <paramref name="dictionary" /> .
Returns A <typeparamref name="TValue" /> instance. When the method is successful, the returned object is the value associated with the specified <paramref name="key" /> . When the method fails, it returns the <see langword="default" /> value for <typeparamref name="TValue" /> .
dictionary
A dictionary with keys of type <typeparamref name="TKey" /> and values of type <typeparamref name="TValue" /> .
key
The key of the value to get.
public static
TValue
GetValueOrDefault​(IReadOnlyDictionary<​TKey, TValue> dictionary,
TKey key,
TValue defaultValue)
Tries to get the value associated with the specified <paramref name="key" /> in the <paramref name="dictionary" /> .
Returns A <typeparamref name="TValue" /> instance. When the method is successful, the returned object is the value associated with the specified <paramref name="key" /> . When the method fails, it returns <paramref name="defaultValue" /> .
dictionary
A dictionary with keys of type <typeparamref name="TKey" /> and values of type <typeparamref name="TValue" /> .
key
The key of the value to get.
defaultValue
The default value to return when the <paramref name="dictionary" /> cannot find a value associated with the specified <paramref name="key" /> .
public static
void
InsertRange​(List<​T> list,
int index,
ReadOnlySpan<​T> source)
Inserts the elements of a span into the <see cref="T:System.Collections.Generic.List`1" /> at the specified index.
list
The list into which the elements should be inserted.
index
The zero-based index at which the new elements should be inserted.
source
The span whose elements should be added to the <see cref="T:System.Collections.Generic.List`1" /> .
public static
bool
Remove​(IDictionary<​TKey, TValue> dictionary,
TKey key,
TValue& value)
public static
bool
TryAdd​(IDictionary<​TKey, TValue> dictionary,
TKey key,
TValue value)
Tries to add the specified <paramref name="key" /> and <paramref name="value" /> to the <paramref name="dictionary" /> .
Returns <see langword="true" /> when the <paramref name="key" /> and <paramref name="value" /> are successfully added to the <paramref name="dictionary" /> ; <see langword="false" /> when the <paramref name="dictionary" /> already contains the specified <paramref name="key" /> , in which case nothing gets added.
dictionary
A dictionary with keys of type <typeparamref name="TKey" /> and values of type <typeparamref name="TValue" /> .
key
The key of the value to add.
value
The value to add.
public static
ObjectModel.​ReadOnlyCollection<​T>
AsReadOnly​(IList<​T> list)
Returns a read-only <see cref="T:System.Collections.ObjectModel.ReadOnlyCollection`1" /> wrapper for the specified list.
Returns An object that acts as a read-only wrapper around the current <see cref="T:System.Collections.Generic.IList`1" /> .
list
The list to wrap.
public static
ObjectModel.​ReadOnlySet<​T>
AsReadOnly​(ISet<​T> set)
<para>Returns a read-only <see cref="T:System.Collections.ObjectModel.ReadOnlySet`1" /> wrapper for the specified set.</para>
Returns An object that acts as a read-only wrapper around the current <see cref="T:System.Collections.Generic.ISet`1" /> .
set
The set to wrap.
public static
ObjectModel.​ReadOnlyDictionary<​TKey, TValue>
AsReadOnly​(IDictionary<​TKey, TValue> dictionary)
Returns a read-only <see cref="T:System.Collections.ObjectModel.ReadOnlyDictionary`2" /> wrapper for the current dictionary.
Returns An object that acts as a read-only wrapper around the current <see cref="T:System.Collections.Generic.IDictionary`2" /> .
dictionary
The dictionary to wrap.
public
bool
Equals​(object obj)
Inherited from object
protected
void
Finalize​()
Inherited from object
public
int
GetHashCode​()
Inherited from object
protected
object
MemberwiseClone​()
Inherited from object
public
string
ToString​()
Inherited from object