Doing some Regular Expression work, and I wanted to get a simple enumeration of multiple captures in a match group. I tried this:
var caps = from capture in match.Groups.Captures select capture.Value;
but Intellisense told me “Could not find an implementation of the query pattern for source type ‘System.Text.RegularExpressions.CaptureCollection’. ‘Select’ not found. Consider explicitly specifying the type of the range variable ‘capture’.”
This is because Captures is a specialised collection, not a generic collection, and it doesn’t therefore support IEnumerable<T>. The solution (which I found here) is:
var caps = from capture in pathmatch.Groups.Captures.Cast<Capture>() select capture.Value;
adding the Cast to a Capture allows the rest of the Linq query to work.
I love Linq, but just sometimes, it can be a bit impenetrable.