LINQ First() ElementIn LINQ, the First () method/operator is used to return the first element from the sequence of the items in the list or collection or the first element in the sequence of items in the list based on the specified condition. In case if no element is present in the list/collection based on the specified condition, then LINQ FIRST () method will throw an error. Syntax of LINQ FIRST () methodThe syntax of the first method to get the first element from the list is: From the above syntax, we are getting the first element from the "objList" collection using the LINQ FIRST () method. Example of LINQ FIRST () methodHere is the example of the LINQ FIRST () operator in method syntax to get the first element from the collection. C# Code From the above example, we are trying to get the first element from the collection of "objList" by using the LINQ FIRST () operator in method syntax. Output: The result of the LINQ FIRST () operator in method syntax is as shown below: Example of LINQ FIRST () operator in Query SyntaxHere is the example of the LINQ FIRST () operator in method syntax to get the first element from the collection. Output: The result of the LINQ FIRST () operator in method syntax is as shown below:
Next TopicLINQ FirstOrDefault() Method
|