LINQ Cheat Sheet
A while ago when I was learning LINQ I searched the web for a 'cheat sheet'. I needed a single document that covered most of the common scenarios w.r.t LINQ so that I would not need to google every time I was writing LINQ queries. I found one very good one : http://aspnetresources.com/blog/linq_sqo__cheat_sheet.aspx . But I wanted more (as usual) so I created my own. I was also new to lambda expressions and I wanted to learn the differences between syntax in a LINQ query written in 'query syntax' and 'lambda syntax' so I also included that as part of my cheat sheet. Every query is given in both syntaxes. Here is a screenshot:
Please let me know what you think. Did it help you? Where could it be improved? What would you add?
You can also download the code that I used when creating the document. It also includes basic testing to make sure the queries of both syntaxes returned the same results. Beware as it may contain some bugs ;)
UPDATE (3 Nov 2008) : I updated the cheat sheet document. Changes made:
- made the left and right margins smaller
- adjusted column widths to be equal
- added new example under 'Ordering' section (thanks to RichardD - see comments)
- added new example under 'Element Operators' section and updated notes (thanks to RichardD - see comments)