I had been putting off using / learning linq for a little while, but am now finally writing some .net 3.5 code for SharePoint where there are some clear uses for it. I am finding it really intuitive.
Anyway, below is one of my first real-world linq queries – it is a simple query to get all of the descendant content types from a given content type (note that the parent content type is also included):
SPContentTypeId parentId = new SPContentTypeId(“parentContentTypeId”);
using (SPSite mySiteCollect= new SPSite(“http://url/to/my/spweb”))
using (SPWeb website = siteCol.OpenWeb())
IEnumerable<SPContentType> descendantContentTypes =
from SPContentType childCt in myspweb.AvailableContentTypes
// Do something here with descendant content types