The element operators are used to return a single, or a specific element from the sequence or collection. For example, in a school when we ask, who is the principal? Then there will be only one person that will be the principal of the school. So the number of students is a collection and the principal is the only result that comes from the collection.
The LINQ Standard Query Operator supports 8 types of element operators:
The ElementAt operator is used to return an element from the particular index from the given collection or sequence. Here the specified index is zero-based index. Suppose an array contains 3 elements, i.e, 1, 2, 3 and we want to print the value at index 1, so we use an ElementAt method because it will return the element present at index 1, i.e, 2.
- It does not support query syntax in C# and VB.Net languages.
- It support method syntax in both C# and VB.Net languages.
- It present in both the Queryable and Enumerable class.
- If the given index is out of range, then this method will throw an ArgumentOutOfRangeException.
Sequence is: Dog Cat Cow Goat Parrot Element is: Goat
Employee ID: 210