LINQ Single() MethodIn LINQ, the Single() method is used to return the single element from the collection, which satisfies the condition. In case, if the Single() method found more than one element in collection or no element in the collection, then it will throw the "InvalidOperationException" error. Syntax of LINQ Single () MethodThe syntax of using the LINQ Single () method to get a single element from the collection. In the above syntax, we are getting the single element from the list using LINQ Single () method. Example of LINQ Single () MethodHere is the example of the LINQ Single () method to get a single element from the collection. From the above example, we are getting the single element from the collection "objStudent" using the LINQ Single() operator. OUTPUT:
Next TopicLINQ SingleOrDefault Method
|