in what situation will an item in System.Collections.Generic.List not be removed successfully?
From http://msdn.microsoft.com/en-us/library/cd666k3e.aspx:
true if item is successfully removed; otherwise, false. This method also returns false if item was not found in the List(Of T).
The way they phrase it makes me think that it is possible that a Remove operation on an item found in the List(Of T) could actually fail, hence this question.
Contains interfaces and classes that define generic collections, which allow users to create strongly typed collections that provide better type safety and performance than non-generic strongly typed collections.
The Remove method removes the first occurrence of a specific object from a List. The Remove method takes an item as its parameter. We can use the RemoveAt method to remove an item at the specified position within a List. The Remove method removes the first occurrence of a specific object from a List.
Looking at the System.Collections.Generic.List source in Reflector, it would appear that the item not being found in the collection is indeed the only way for Remove to return false.
int index = this.IndexOf(item);
if (index >= 0)
{
this.RemoveAt(index);
return true;
}
return false;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With