Click here to Skip to main content
15,888,802 members
Articles / Programming Languages / C# 3.5

LINQ (Single, SingleOrDefault)

Rate me:
Please Sign up or sign in to vote.
2.45/5 (3 votes)
16 Dec 2009CPOL 22.6K   2  
I sometimes get asked how to get a single object from a generic list based on a LINQ query. i.e. Performing a LINQ query on a generic collection and then returning only the single instance without looping through the collection. Well this is how I do it:public class Person{ public...

Views

Daily Counts

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Architect Kohde.io
South Africa South Africa
I escaped from the mental hospital on 25th June and was captured by a zookeeper. Escaped from the zoo on 15th July and killed the zoo guard in the attempt. So now I just eat bananas and hang out on the Code Project.

Comments and Discussions