Class CollectionExtensions
Provides extension methods for collections.
Inheritance
Namespace: System.Linq.CompilerServices
Assembly: Nuqleon.Linq.CompilerServices.dll
Syntax
public static class CollectionExtensions : Object
Methods
AsArray<T>(IEnumerable<T>)
Converts the specified sequence to an array. If the specified sequence is null, an empty array is returned. If the specified sequence is already an array, it gets returned after type conversion. Otherwise, an array is created with the sequence's elements.
Declaration
public static T[] AsArray<T>(this IEnumerable<T> enumerable)
Parameters
Type | Name | Description |
---|---|---|
System.Collections.Generic.IEnumerable<T> | enumerable | Sequence to get an array representation for. |
Returns
Type | Description |
---|---|
T[] | Array containing the elements of the specified sequence. |
Type Parameters
Name | Description |
---|---|
T | Type of the elements in the sequence. |
AsCollection<T>(IEnumerable<T>)
Converts the specified sequence to a collection. If the specified sequence is null, an empty array is returned. If the specified sequence is already a collection, it gets returned after type conversion. Otherwise, a collection is created with the sequence's elements.
Declaration
public static ICollection<T> AsCollection<T>(this IEnumerable<T> enumerable)
Parameters
Type | Name | Description |
---|---|---|
System.Collections.Generic.IEnumerable<T> | enumerable | Sequence to get a collection representation for. |
Returns
Type | Description |
---|---|
System.Collections.Generic.ICollection<T> | Collection containing the elements of the specified sequence. |
Type Parameters
Name | Description |
---|---|
T | Type of the elements in the sequence. |
ToReadOnly<T>(IEnumerable<T>)
Gets a read-only collection containing the elements of the specified sequence. If the specified sequence is null, an empty collection is returned.
Declaration
public static ReadOnlyCollection<T> ToReadOnly<T>(this IEnumerable<T> enumerable)
Parameters
Type | Name | Description |
---|---|---|
System.Collections.Generic.IEnumerable<T> | enumerable | Sequence to get a read-only collection for. |
Returns
Type | Description |
---|---|
System.Collections.ObjectModel.ReadOnlyCollection<T> | Read-only collection containing the elements of the specified sequence. |
Type Parameters
Name | Description |
---|---|
T | Type of the elements in the sequence. |