Suppose I have two affine varieties $X_1, X_2 \in \mathbb{A}^n_{\mathbb{C}}$. Let $U$ be a Zariski-open set. Suppose I know that $$ \emptyset \not = X_1 \cap U = X_2 \cap U. $$ Does it then follow that $\dim X_1 = \dim X_2$? I think it does... Any comments are appreciated. Thank you very much!
Edit: Without the assumption of irreducibility the statement is not true, as shown in the comments. So I would like to suppose we know $X_1$ and $X_2$ are irreducible, and how to prove it in this case.