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?
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: