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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T09:53:15+00:00 2026-05-25T09:53:15+00:00

I am having trouble remembering how (but not why) to use IEnumerator s in

  • 0

I am having trouble remembering how (but not why) to use IEnumerators in C#. I am used to Java with its wonderful documentation that explains everything to beginners quite nicely. So please, bear with me.

I have tried learning from other answers on these boards to no avail. Rather than ask a generic question that has already been asked before, I have a specific example that would clarify things for me.

Suppose I have a method that needs to be passed an IEnumerable<String> object. All the method needs to do is concatenate the letters roxxors to the end of every String in the iterator. It then will return this new iterator (of course the original IEnumerable object is left as it was).

How would I go about this? The answer here should help many with basic questions about these objects in addition to me, of course.

  • 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-25T09:53:16+00:00Added an answer on May 25, 2026 at 9:53 am

    Here is the documentation on IEnumerator. They are used to get the values of lists, where the length is not necessarily known ahead of time (even though it could be). The word comes from enumerate, which means “to count off or name one by one”.

    IEnumerator and IEnumerator<T> is provided by all IEnumerable and IEnumerable<T> interfaces (the latter providing both) in .NET via GetEnumerator(). This is important because the foreach statement is designed to work directly with enumerators through those interface methods.

    So for example:

    IEnumerator enumerator = enumerable.GetEnumerator();
    
    while (enumerator.MoveNext())
    {
        object item = enumerator.Current;
        // Perform logic on the item
    }
    

    Becomes:

    foreach(object item in enumerable)
    {
        // Perform logic on the item
    }
    

    As to your specific scenario, almost all collections in .NET implement IEnumerable. Because of that, you can do the following:

    public IEnumerator Enumerate(IEnumerable enumerable)
    {
        // List implements IEnumerable, but could be any collection.
        List<string> list = new List<string>(); 
    
        foreach(string value in enumerable)
        {
            list.Add(value + "roxxors");
        }
        return list.GetEnumerator();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Having trouble with proper regex for RewriteCond RewriteCond %{REQUEST_URI} !^/foo/ Works as expected, that
Having trouble with this -- a couple of other related posts out there, but
having trouble deciding whether or not it makes sense to put paging information about
Having trouble installing play! on windows. Following the installation guide on: http://www.playframework.org/documentation/1.2.4/install After installing
Having trouble here and not quite sure how to do it. I've attempted jQuery
Having trouble with this..I'm sure I'm missing something simple but I simply want the
I'm having some trouble remembering my database queries - it's been a while :(
My highschool years are far behind and I'm having trouble remembering how to isolate
Having trouble with the binary_search function listed at the top. not sure where to
Having trouble with a horizontal scroll bar that pops up. My page is set

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.