5. For the range of values of the independent variable $x$, $n \leqslant x \leqslant n+1$ (where $n$ is a natural number), the number of integer values of the quadratic function $y=x^{2}+x+\frac{1}{2}$ is ( ).
(A) $n$
(B) $n+1$
(C) $2 n$
(D) $2(n+1)$
5. (D).

The function $y=\left(x+\frac{1}{2}\right)^{2}+\frac{1}{4}$, when $x>-\frac{1}{2}$, the function value increases as the independent variable increases. Therefore, when $n \leqslant x \leqslant n+1$, we have
$$
n^{2}+n+\frac{1}{2} \leqslant y \leqslant(n+1)^{2}+(n+1)+\frac{1}{2} \text {. }
$$

Since $y$ is an integer, we have
$$
n^{2}+n \leqslant y \leqslant(n+1)^{2}+n+1 \text {. }
$$

Thus, the number of integers is
$$
(n+1)^{2}+n+1-\left(n^{2}+n\right)+1=2(n+1) .
$$