I have Collection List<Car>
.
How to compare each item from this collection with rest without repeatition.
Ex:
- iteration:
this car is Audi and secondCar is BMW
bool IsSimilar(Car secondCar)
{
if(this.Name==secondCar.Name) return true;
return false;
}
this is not permitted:
n iteration
this car is BMW and secondCar is Audi
bool IsSimilar(Car secondCar)
{
if(this.Name==secondCar.Name) return true;
return false;
}
Clearer:
List<Car> car=new List<Car>();
List<Pair> pairs=new List<Pair>();
pairs.Cars=new List<Car>();
foreach(Car car in cars)
{
foreach(Car secondCar in cars)
{
if(secondCar!=car)
{
if(car.Name==secondCar.name && car.Owner==secondCar.Owner)
{
Pair pair=new Pair();
pair.Cars.Add(car);
pair.Cars.Add(secondCar);
pairs.Add(pair);
}
}
}
}
I'm just don't want to compare cars twice(you know first iteration compare car 1 with car2, next car2 is base car and car1 is secondCar)
Sorry for my terrible English