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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T10:02:14+00:00 2026-05-15T10:02:14+00:00

Possible Duplicates: Exception during iteration on collection and remove items from that collection How

  • 0

Possible Duplicates:
Exception during iteration on collection and remove items from that collection
How to remove elements from a generic list while iterating around it?
Better way to remove matched items from a list

// tmpClientList is List<Client> type

if (txtboxClientName.Text != "")
    foreach (Client cli in tmpClientList)
        if (cli.Name != txtboxClientName.Text)
            tmpClientList.Remove(cli);

Error: “Collection was modified; enumeration operation may not execute.”

How can i remove items from the list, in some simple way, without saving indexes of these items in another list or array, and removing them in another place in the code. Tried also RemoveAt(index) but it’s exactly the same situation, modifying when loop runs.

  • 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-15T10:02:14+00:00Added an answer on May 15, 2026 at 10:02 am

    The problem is that you are trying the modify the list in a foreach iteration. Replace that with a for and you should be ok.

    Also, since you seem to be using user input for the name, consider cleaning up the input a bit, at least with a Trim() to remove extra white spaces. If you don’t, ‘John ‘ and ‘John’ will be two different things.
    Same for the initial != “” check.

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

Sidebar

Related Questions

Possible Duplicate: Getting exception as “Collection was mutated while being enumerated” This question is
Possible Duplicate: Runtime exception, recursion too deep I'm getting a problem while developing a
Possible Duplicate: Should I derive custom exceptions from Exception or ApplicationException in .NET? I've
I'm adding items to a StringDictionary and it's possible that a duplicate key will
Possible Duplicate: ArgumentNullException or NullReferenceException from extension method? Which exception should be thrown here?
Possible Duplicate: Why can’t I catch a generic exception in C#? I have been
Possible Duplicate: Concurrent Modification Exception : adding to an ArrayList I'm attempting to remove
Possible Duplicate: Why do I get a null pointer exception from TabWidget? I have
Possible Duplicates: Exception in thread “main” java.lang.NoClassDefFoundError: DiServer <wrong name: ds/DiServer> java.lang.NoClassDefFoundError when i
Possible Duplicates: How can I get the size of an array from a pointer

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.