One of the best ways of understanding something is to implement it yourself.
To that end Jon Skeet has already documented how to do it in his Edulinq series[0][1].
[0] Link to series: http://msmvps.com/blogs/jon_skeet/archive/tags/Edulinq/defau...
[1] Download of series (found in link): https://code.google.com/p/edulinq/downloads/list