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

  • Home
  • SEARCH
  • 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 3789716
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T12:12:03+00:00 2026-05-19T12:12:03+00:00

I have writen about custom IEnumerator . Whats the simplest way to make IEnumerable

  • 0

I have writen about custom IEnumerator. Whats the simplest way to make IEnumerable from it ? Ideal solution (one line of code) would be if there was some class for that purpose. Or do I have to create my own ?

  • 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-19T12:12:03+00:00Added an answer on May 19, 2026 at 12:12 pm

    I would really approach this the other way around; while you can (as per Mike P’s excellent answer) wrap an enumerator to pretend to be enumerable, there are some things that you can’t really do – for example, it is hoped (although, to be fair, not insisted) that you can obtain multiple enumerators from an enumerable, ideally isolated and repeatable. So if I do:

    Assert.AreEqual(sequence.Sum(), sequence.Sum());
    

    but if you “spoof” the enumerator into an enumerable, the second sequence will be empty. Or if you do them in parallel – just bizarre. And there are methods that process them in parallel – consider:

    Assert.IsTrue(sequence.SequenceEqual(sequence));
    

    this works both enumerators forward at the same time, so if you only have one enumerator, you are fairly scuppered.

    There is a reset on enumerators, but this is largely a design mistake and shouldn’t be used (it is even a formal requirement in the spec that iterator blocks throw an exception if you call it).

    A better (IMO) question is “how do I get an enumerator from an enumerable”, in which case the answer is “call GetEnumerator(), and remember to check to dispose to iterator” – or in simpler terms “use foreach“.

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

Sidebar

Related Questions

I have seen a similar line of code floating about in Apples code: (void)[[URLRequest
What are your thoughts about them? Sometimes I have to write unmanaged code at
I have about 150 000 rows of data written to a database everyday. These
I have this little function function makewindows(){ child1 = window.open (about:blank); child1.document.write(<?php echo htmlspecialchars(json_encode($row2['ARTICLE_DESC']),
Recently, I found myself having to write up some concerns I have about race
I have written an AIR Application that downloads videos and documents from a server.
I have a custom layout that I have written that basically just displays a
I have written an IIS module (base IHttpModule) that does some custom (OpenAuth) authentication
I have created some custom PowerShell Cmdlets in C# and would like to provide
Many questions here on SO ask about custom classes. I, on the other hand,

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.