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 Last operator is used to return the last element of the collection or sequence. Or return the last element which specifies the given condition. Or return the default value if the given collection does not contain any element. It overcomes the InvalidOperationException problem of the Last method. This method can be overloaded in two different ways:
- LastOrDefault<TSource>(IEnumerable<TSource>): This method returns the last element of a sequence, or a default value if the sequence contains no elements.
- LastOrDefault<TSource>(IEnumerable<TSource>, Func<TSource, Boolean>): This method returns the last element of a sequence that satisfies a condition or a default value if no such element is found.
- 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.
- The default value of the reference types and the nullable types is null.
Element: 56 Element: GeeksforGeeks Default value: 0
Employee Id: 214
- LINQ | Element Operator | Last
- LINQ | Element Operator | First
- LINQ | Element Operator | Single
- LINQ | Element Operator | SingleOrDefault
- LINQ | Element Operator | ElementAtOrDefault
- LINQ | Element Operator | ElementAt
- LINQ | Element Operator | FirstOrDefault
- LINQ | Set Operator | Except
- LINQ | Set Operator | Intersect
- LINQ | Set Operator | Distinct
- LINQ | Filtering Operator | where
- LINQ | Quantifier Operator | Contains
- LINQ | Quantifier Operator | All
- LINQ | Set Operator | Union
- LINQ | Quantifier Operator | Any
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.