..NET 2.0
I'm trying to use List.Contains to determine if an object already exist in
the list. This Contains method always return false in my code
In my code a method gets a list of names, the method will return a generic
list containing only the distinct names. This fails in my code
Example:
public class Car
[Serializable]
private string _name;
public Car(string name) { _name = name; }
}
List<Carcars = List<Car>();
Car car = new Car("Volvo");
list.Add(car);
car = new Car("Volvo");
if (!list.Contains(car))
List.Add(car) <<<<<<<<<<<< here is the problem in my code, Here
Contains didn't find the car("Volvo") already in the list, so this
if-statement fails and another car(volvo) object is added to the list
Maybe I instead should use Exists?
Any suggestions are welcome