I have two variables CarsSelected
and PlanesSelected
. If someone sets one of them I want the other variable to be set to the opposite value, so if one is true, the other one has to be false and vice versa. Therefore both variables in the end are always different. My problem is my code goes to into infinite loop
when changing any value. How to fix it?
public class MyClass
{
private bool _carsSelected;
private bool _planesSelected;
public bool CarsSelected
{
get => _carsSelected;
set
{
_carsSelected= value;
PlanesSelected= !_carsSelected;
}
}
public bool PlanesSelected
{
get => _planesSelected;
set
{
_planesSelected= value;
CarsSelected= !_planesSelected;
}
}
public MyClass()
{
CarsSelected= false;
PlanesSelected= false;
}
}