Method ElementAt
ElementAt<TSource>(IEnumerable<TSource>, Index)
Returns the element at a specified index in a sequence.
Declaration
[Obsolete("This method has been implemented by the framework.")]
public static TSource ElementAt<TSource>(IEnumerable<TSource> source, Index index)
Parameters
| Type | Name | Description |
|---|---|---|
| IEnumerable<TSource> | source | An IEnumerable<T> to return an element from. |
| Index | index | The index of the element to retrieve, which is either from the start or the end. |
Returns
| Type | Description |
|---|---|
| TSource | The element at the specified position in the |
Type Parameters
| Name | Description |
|---|---|
| TSource | The type of the elements of |
Remarks
If the type of source implements IList<T>, that implementation is used to
obtain the element at the specified index. Otherwise, this method obtains the specified element.
This method throws an exception if index is out of range. To instead return a default
value when the specified index is out of range, use the ElementAtOrDefault<TSource>(IEnumerable<TSource>, Index) method.
This operator is implemented in the bcl as of net6. Source and binary compatibility should be retained across net versions, but this method should be inaccessible in net6+.
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException |
|
| ArgumentOutOfRangeException |
|