I saw several proofs of $\mathbb{E}[X] = \int_0^\infty (1-F(x)) \ dx$ where $F(x)$ denotes CDF, the standard one looks like this:
$$ \begin{align} \int_0^\infty (1-F(x)) \mathrm{d}x &= \int_0^\infty \left[ \int_0^\infty f(t)\mathrm{d}t - F(x) \right]\mathrm{d}x\newline &= \int_0^\infty \left[ \int_0^\infty f(t)\mathrm{d}t - \int_0^xf(t)\ \mathrm{d}t \right] \mathrm{d}x\newline &= \int_0^\infty \int_x^\infty f(t)\;\mathrm{d}t\mathrm{d}x\newline &= \int_0^\infty \int_0^t f(t)\;\mathrm{d}x\mathrm{d}t\newline &= \int_0^\infty f(t)t\ \Big|_0^t\;\mathrm{d}t\newline &= \int_0^\infty f(t)t\;\mathrm{d}t\newline &=\mathbb{E}[X].\square \end{align} $$
Using the same technique, I find that it's also true for any range of $X$ not just $[0, \infty)$. That is if X takes the value in the range $[0, b]$ for $b\in\mathbb{R}, b\gt 0$ then:
$$ \mathbb{E}[X] = \int_0^b(1-F(x)) \ \mathrm{d}x. $$
But I'm not sure if something mysteriously goes wrong when I change the limit of integration? If nothing wrong then I'm wondering why the formula has been generalized as such.