I am now studying undergraduate level real analysis, and the professor gives us an example of taking the indefinite integral of a real function by its Taylor series, and here is the example given by my professor:
Let $f(x) = e^x$, then by Taylor series, we have
\begin{equation} e^x = \sum_{n=0}^{\infty} \frac{x^n}{n!} \cdots (1)\end{equation}
And then, take the indefinite integral of $(1)$, we get
$$\begin{aligned} \int e^x dx &= \int \sum_{n=0}^{\infty} \frac{x^n}{n!} dx \\ &= \sum_{n=0}^{\infty} \int \frac{x^n}{n!} dx \cdots (*) \\ &= \sum_{n=0}^{\infty} \frac{x^{n+1}}{(n+1)!} + C \\ &= \sum_{n=-1}^{\infty} \frac{x^{n+1}}{(n+1)!} + (C -1) \\ &= \sum_{m=0}^{\infty} \frac{x^{m}}{m!} + D \\ &= e^x + D \end{aligned}$$
where $D$ is a constant.
Now my question is, for the step marked with $(*)$, why can we switch the order of $\int$ and $\sum$, and in general under what circumstances can we switch them? Can someone tell me which theorems and conclusions that I need to know to study this more deeply? Thanks!