Does comparing two GameObjects with "==" works?

I have an in-game phone and need it to change between screens, so I made a property that enables the given screen and disable others:

private AppScreen InitialScreen;
private AppScreen activeScreen;
public AppScreen ActiveScreen
    get => activeScreen;
        activeScreen = value;
        foreach (Transform screen in transform)
            Debug.Log($"({} == {}) = {screen == activeScreen}");
            screen.gameObject.SetActive(screen == activeScreen);

void Start()
    ActiveScreen = InitialScreen;

The class has an Initial screen that is activated in the Start() method. This screen and another are the only children of this class.

That foreach is used to iterate over all screens and disable the screen if it isn’t the active one.

But instead it deactivates both screens, so I made a debug, and it looks kinda funny:

My question is: Why this happens and how could I fix that? Thanks

Yes, == works to compare game objects.

However, the issue you’re experiencing is using == to compare Transforms to AppScreens. I.e., comparing two different types of components (which always returns false, ignoring cases of polymorphism).

What you probably meant to do is compare their game objects ( screen.gameObject == activeScreen.gameObject ).