Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3323438
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T23:18:10+00:00 2026-05-17T23:18:10+00:00

I wanted to use Jon Skeet’s SmartEnumerable to loop over a Regex.Matches but it

  • 0

I wanted to use Jon Skeet’s SmartEnumerable to loop over a Regex.Matches but it does not work.

foreach (var entry in Regex.Matches("one :two", @"(?<!\w):(\w+)").AsSmartEnumerable())

Can somebody please explain me why? And suggest a solution to make it work. Thanks.

The error is:

'System.Text.RegularExpressions.MatchCollection' does not contain a definition
for 'AsSmartEnumerable' and no extension method 'AsSmartEnumerable' accepting
a first argument of type 'System.Text.RegularExpressions.MatchCollection' could
be found (are you missing a using directive or an assembly reference?)
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T23:18:10+00:00Added an answer on May 17, 2026 at 11:18 pm

    EDIT: I think you forgot to insert the .AsSmartEnumerable() call in your sample code. The reason that won’t compile is because the extension-method only works on IEnumerable<T>, not on the non-generic IEnumerable interface.


    It’s not that you can’t enumerate the matches that way; it’s just that the type of entry will be inferred as object since the MatchCollection class does not implement the generic IEnumerable<T> interface, only the IEnumerable interface.

    If you want to stick with implicit typing, you will have to produce an IEnumerable<T> to help the compiler out:

    foreach (var entry in Regex.Matches("one :two", @"(?<!\w):(\w+)").Cast<Match>())
    { 
       ...
    } 
    

    or, the nicer way with explicit-typing (the compiler inserts a cast for you):

    foreach (Match entry in Regex.Matches("one :two", @"(?<!\w):(\w+)"))
    { 
       ...
    } 
    

    The easiest way to produce a smart-enumerable is with the provided extension-method:

    var smartEnumerable = Regex.Matches("one :two", @"(?<!\w):(\w+)")
                               .Cast<Match>()
                               .AsSmartEnumerable();
    
    foreach(var smartEntry in smartEnumerable)
    {
       ...
    }
    

    This will require a using MiscUtil.Collections.Extensions; directive in your source file.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I recently wanted use regex in Cocoa app. But I found that Cocoa does
I wanted to use http://arborjs.org/atlas/ plugin ,but the plugin is not working in IE.
I wanted to use an ExpandableListView for my Fragment but since it's not native,
I thought I wanted to use GSS-API, but now am not so sure, since
I wanted to use the StatusBarManagerService, but it's not available on the SDK, so
I wanted use MVC and renderpartial to generate a menu but but could not
I wanted to use JET (Java Emitter Templates) in my Netbeans projects, but had
I wanted to use monotouch, but unfortunately I don't have $400 to spend. So
I wanted to use {-# LANGUAGE OverloadedStrings #-} but I forgot how it's called.
I wanted to use .net's System.IO.Compression.GZipStream to compress and decompress a directory. But I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.