According to the documentation, the GroupCollection Class implements the generic IEnumerable interface. Its extension methods are even listed below on that page. Yet, I'm getting
Compilation error (line 16, col 4): 'GroupCollection' does not contain a definition for 'Skip' and no accessible extension method 'Skip' accepting a first argument of type 'GroupCollection' could be found (are you missing a using directive or an assembly reference?)
for the following code:
using System.Linq;
var currency = "HUF";
var origin = "Modlin";
var changes = 3;
System.Console.WriteLine(
new[] {
$"Cost: 50 {currency}",
$"Departure airport: {origin}",
$"Number of changes: {changes}"
}[
System.Text.RegularExpressions.Regex.Matches(
"variable elem: blablaoriginbleble",
"(currency)|(origin)|(changes)"
)[0]
.Groups
.Skip(1)
.Select((m, i) => (m, i))
.First(p => p.Item1.Success)
.Item2
]);
The error goes away if I surround L11-15 with ((System.Collections.Generic.IEnumerable<System.Text.RegularExpressions.Group>) and ). Why is it necessary?
What's even stranger is that omitting [0] and .Groups (not semantically equivalent, just for the sake of experiment) leads to no error as well. In that case the extension methods Skip, Select and First are called on an instance of MatchCollection. Which also implements IEnumerable and it seems behaviour should be analogous.