Method ElementAtOrDefault
View SourceElementAtOrDefault<TSource>(IEnumerable<TSource>, Index)
Returns the element at a specified index in a sequence or a default value if the index is out of range.
Declaration
[Obsolete("This method has been implemented by the framework.")]
public static TSource? ElementAtOrDefault<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 | default if |
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 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 |
|