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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T10:49:45+00:00 2026-06-12T10:49:45+00:00

Code: public List<Interfaces.Test> IJ_; IEnumerator<Interfaces.Test> Ij_ = Objects.GetEnumerator(); int count = IJ_.Count; Ij_.MoveNext(); for

  • 0

Code:

public List<Interfaces.Test> IJ_;
IEnumerator<Interfaces.Test> Ij_ = Objects.GetEnumerator();
int count = IJ_.Count;
Ij_.MoveNext();
for (int x = 0; x < count; x++)
{
    if (x >= count)
        break;
    Test MyBase = IJ_.Current;
    if (MyBase == null)
        obj_.MoveNext(); //here the error
}

Error:

System.InvalidOperationException: Collection was modified; enumeration operation may not execute.
at System.ThrowHelper.ThrowInvalidOperationException(ExceptionResource resource)
at System.Collections.Generic.List`1.Enumerator.MoveNextRare()
at System.Collections.Generic.List`1.Enumerator.MoveNext()

Please help me.

  • 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-06-12T10:49:47+00:00Added an answer on June 12, 2026 at 10:49 am

    As the error says, the collection is modified during the iteration, which is an illegal operation.

    Either way, the right way to iterate using an enumerator is this:

    var Ij_ = Objects.GetEnumerator();
    
    while (Ij.MoveNext())
    {
        Test MyBase = IJ_.Current;
    
        // I understood that you want to skip null elements, so...
        if (MyBase == null)
        {
            continue;
        }
    
        // ...
    }
    

    You should make sure that you don’t add, remove or set items in the collection during the iteration (not in the loop, and not in a different thread). Changing an element’s inner state is allowed.

    If the enumerator is your implementation, and the error still occurs after assuring that the collection is not modified during the iteration, it might be helpful to post the enumerator’s code as well.

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

Sidebar

Related Questions

I have code similar to this: public List<string> Expected = new List<string>(); public int
The code looks like below: namespace Test { public interface IMyClass { List<IMyClass> GetList();
Say I have this code - public interface ParentInterface1 { public List<? extends ChildInterface1>
The code is also at https://github.com/timp21337/java-generics-example package a; import java.util.List; public interface Container<T> {
I have the following code: public List<IWFResourceInstance> FindStepsByType(IWFResource res) { List<IWFResourceInstance> retval = new
The original code: public List<Contact> GetContactListEntityCompiledLINQ() { if (entities == null) entities = new
what is wrong with such code public List<SearchItem> Search(string find) { return (from i
Consider the following C# code: [XmlRoot] public class A { [XmlArray] public List<B> ArrayOfBItems
i have the following code: public static void Serialize() { List<string> dirs = FileHelper.GetFilesRecursive(fileDirectoryPath);
Given this piece of code : public static void writeFile(File file,List buffer)throws IOException{ File

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.