I am reading the answer in the post Continuity of Rational Maps in Zariski Topology, where the answerer mentioned the following lemma (sounds like an elementary fact but I fail to prove it):
Lemma: Let $S\subseteq X$ and $\{U_i\}_{i\in I}$ be an open covering of $X$, then $S$ is closed in $X$ iff $S\cap U_i$ is closed in each $U_i$.
My attempt: When $S\cap U_i$ is closed in $U_i$, we get: $$ S=\bigcup_{i\in I} (S_i\cap U_i)$$ where $S_i$ is closed in $X$. But how to proceed?
Any hints or references are welcomed. Thanks!