C# List<T> Contains test
c#, list
Solution
You don't have to test to remove. Remove() will return false if it didn't remove anything.
If you don't want duplicate items in your list you can test, before adding. Otherwise, you'll have duplicates.
See also: http://msdn.microsoft.com/en-us/library/6sh2ey19.aspx
Problem
Is this kind of if-testing necessary when removing an item? ``` if (_items.Contains(item)) { _items.Remove(item); } ``` And, what about this test? ``` if (!_items.Contains(item)) { _items.Add(item); } ```