I wanted to run a LINQ query against a MatchCollection
object but found this wasn't possible as it doesn't implement ICollection<T>
, just ICollection
.
What is the best option for using LINQ with non-generic collections, both in terms of code conciseness but also performance and memory usage?
(If interested, here is the non-LINQuified code:)
MatchCollection fieldValues = Regex.Matches(fieldValue, @"(?<id>\d+);#(?<text>[^;|^$]+)");
foreach (Match m in fieldValues)
{
if (m.Groups["text"].Value.Equals(someString))
{
// Do stuff
}
}