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 787719
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T21:14:58+00:00 2026-05-14T21:14:58+00:00

If I am walking through an IEnumerable<T> , is there any way to get

  • 0

If I am walking through an IEnumerable<T>, is there any way to get a new IEnumerable<T> representing the remaining items after the current one.

For example, I would like to write an extension method IEnumerator<T>.Remaining():

IEnumerable<int> sequence = ...
IEnumerator<int> enumerator = sequence.GetEnumerator();

if (enumerator.MoveNext() && enumerator.MoveNext()) {
    IEnumerable<int> rest = enumerator.Remaining();
    // 'rest' would contain elements in 'sequence' start at the 3rd element
}

I’m thinking of the collection of a sort of singly-linked list, so there should be a way to represent any remaining elements, right? I don’t see any way to do this exposed on either IEnumerable<T> or IEnumerator<T>, so maybe it’s incompatible with the notion of a potentially unbounded, nondeterministic sequence of elements.

  • 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-14T21:14:59+00:00Added an answer on May 14, 2026 at 9:14 pm

    If you must use IEnumerator<T> and not IEnumerable<T> (where all the good extension methods are) here’s two simple methods.

    This one can only be enumerated a single time (and is bound to the original enumerable, which means you can end up with exceptions if another thread changes the source list):

    public static IEnumerable<T> Remaining<T>( this IEnumerator<T> value ) {
        while( value.MoveNext() ) {
            yield return value.Current;
        }
    }
    

    And this one builds a list and can be enumerated repeatedly (and is disconnected from the original enumerator so you don’t have to worry about your source IEnumerable changing):

    public static IEnumerable<T> Remaining<T>( this IEnumerator<T> value ) {
        List<T> list = new List<T>();
        while( value.MoveNext() ) list.Add( value.Current );
    
        return list;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there a jQuery type function to solve the problem of walking through nested
I'm walking through a small example to hit https web services. It requires building
I am walking through the Cython documentation and building each of the example apps.
I was walking through the new html 5 features and I saw and tried
I am walking through a Visual FoxPro program trying to document the code in
I am using the Google Appengine remote shell, with Python. I am walking through
I'm walking through the FrontStore series tutorial on TDD in MVC ( Part 3
I'm walking through a tutorial for Ria services and Silverlight 3 however my coding
I just started learning Silverlight by walking through the labs posted on Channel9. When
I am walking through a xml definition file and I have a DOMNodeList that

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.