© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•4mo ago•
4 replies
ReK

A .Select() that I believe should work but it doesn't.

As title says, this is the script (not my real script just one made to show the issue):
using System;
using System.Text.RegularExpressions;
using System.Linq;


namespace test
{
    class Program
    {
        static void Main()
        {
            MatchCollection matchCollection = Regex.Matches("", "");
            matchCollection.Select(n => n); // works
            GroupCollection groupCollection = matchCollection[1].Groups;
            groupCollection.Select(n => n); // Doesn't work
        }
    }
}
using System;
using System.Text.RegularExpressions;
using System.Linq;


namespace test
{
    class Program
    {
        static void Main()
        {
            MatchCollection matchCollection = Regex.Matches("", "");
            matchCollection.Select(n => n); // works
            GroupCollection groupCollection = matchCollection[1].Groups;
            groupCollection.Select(n => n); // Doesn't work
        }
    }
}


With <GroupCollection> it says
'GroupCollection' does not contain a definition for 'Select' and no accessible extension method 'Select' accepting a first argument of type 'GroupCollection' could be found (are you missing a using directive or an assembly reference?)
'GroupCollection' does not contain a definition for 'Select' and no accessible extension method 'Select' accepting a first argument of type 'GroupCollection' could be found (are you missing a using directive or an assembly reference?)


But it works with <MatchCollection>, and I'm using .NET 8.0 so it isn't an issue about it not having generic interfaces or whatever, why is this happening when both have IEnumerable<T>.

This is their declarations
public class MatchCollection : ICollection<Match>, IEnumerable<Match>, IEnumerable, IList<Match>, IReadOnlyCollection<Match>, IReadOnlyList<Match>, ICollection, IList
public class MatchCollection : ICollection<Match>, IEnumerable<Match>, IEnumerable, IList<Match>, IReadOnlyCollection<Match>, IReadOnlyList<Match>, ICollection, IList

and
public class GroupCollection : ICollection<Group>, IEnumerable<Group>, IEnumerable, IEnumerable<KeyValuePair<string, Group>>, IList<Group>, IReadOnlyCollection<KeyValuePair<string, Group>>, IReadOnlyCollection<Group>, IReadOnlyDictionary<string, Group>, IReadOnlyList<Group>, ICollection, IList
public class GroupCollection : ICollection<Group>, IEnumerable<Group>, IEnumerable, IEnumerable<KeyValuePair<string, Group>>, IList<Group>, IReadOnlyCollection<KeyValuePair<string, Group>>, IReadOnlyCollection<Group>, IReadOnlyDictionary<string, Group>, IReadOnlyList<Group>, ICollection, IList
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

❔ Bool method that doesn't work
C#CC# / help
3y ago
Authorization doesn't work as it should ASP.NET C#
C#CC# / help
2y ago
Parallel.For but that doesn't allocate.
C#CC# / help
3y ago
✅ "view requires a list but it literally doesn't?"
C#CC# / help
9mo ago