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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T17:25:31+00:00 2026-06-07T17:25:31+00:00

Sorry if very primitive question but I am not sure how does this works

  • 0

Sorry if very primitive question but I am not sure how does this works with List, when you call Remove() method and pass to it an object, that in the collection an object with totally same fields and values does already exist.

I have a class like this:

public class Test
{
    private List<string> _names;

    public void Add(string name)
    {
        _names.Add(name);
    }

   public void Remove(string name)
   {
        _names.Remove(name)
   }
}

What happens if more than same one (instance) of name are in the list already? Considering calling this Remove method from another class?

  • 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-07T17:25:32+00:00Added an answer on June 7, 2026 at 5:25 pm

    Read the documentation.

    It says for .Remove(T item):

    “Removes the first occurrence of a specific object from the List<T>.”

    If you want to remove all occurences, use .RemoveAll(Predicate<T> match), like so:

    public void Remove(String name) {
        _names.RemoveAll( s => s.Equals( name ) );
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

First of I'm very sorry but this questions is not so so specific. All
Sorry if this question is very easy, but I can't find the answer anywhere.
Sorry this is not a very well defined question, I am thinking about an
I'm very sorry about this being a very cliché question, but I really need
Sorry for the very basic question. What does the & operator do in this
I am sorry for the very newbie question, but this is driving me mad.
First of all, I want to say sorry for this very big question, but
Very sorry for the basic question but I've seen this implemented in so many
Im very sorry if this has been answered before but I have been looking
I am very sorry to ask such a basic question but I am new

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.