I have a terrible feeling that this can lead to a mannequin-on-me situation, a forest behind trees, and if so, mea culpa in advance. But for life, I just donβt understand why the next line will not compile in C #, assuming that myRegEx is a RegEx object, and myString is the target for calling the Match method, as follows:
String[] results = myRegEx.Matches(myString)[0].Groups["Group1"].Captures.Select(x => x.Value).ToArray<String>();
The .Captures link should lead me to a CaptureCollection that implements IEnumerable , and IEnumerable offers a Select extension method to convert, as I tried here, hooking the Value property for each item in the collection and pushing it into an array of strings.
However, the compiler barks with me
'System.Text.RegularExpressions.CaptureCollection does not contain a Select definition and do not use the Select extension method to accept the first argument of type System.Text.RegularExpression.CaptureCollection'.
I can overcome this by calling the .Cast<Capture>() method from the Captures object, and then call select with a transformation, which in turn will turn to the Value property, but it seems a little silly if the objects already have Capture objects.
What am I doing wrong? Many thanks in advance for pointing out what should be painfully explicit supervision on my part.
c # regex
David w
source share