5. Given that $n$ is a natural number, $3^{1999}-3^{1998}-3^{1997}+$ $3^{1996}+3^{n+(-1)^{n}}$ is a perfect square. Then the value of $n$ is ( ).
(A) 2000
(B) 1999
(C) 1998
(D) 1997
5.B.

Let the perfect square be $m^{2}$ (where $m$ is a natural number), then the original equation simplifies to
$$
\begin{array}{l}
16 \times 3^{1996} + 3^{n+(-1)^{n}} = m^{2}. \\
\therefore\left(m + 4 \times 3^{998}\right)\left(m - 4 \times 3^{998}\right) = 3^{n+(-1)^{n}}. \\
\text { Let } m + 4 \times 3^{998} = 3^{x}, m - 4 \times 3^{998} = 3^{y}. (x, y \text { are non-negative integers, and } x > y) \text { Eliminating } m, \text { we get } \\
3^{x} - 3^{y} = 8 \times 3^{998}, \\
3^{y}\left(3^{x-y} - 1\right) = 8 \times 3^{998}. \\
\therefore\left\{\begin{array}{l}
3^{y} = 3^{998}, \\
3^{x-y} - 1 = 8.
\end{array}\right.
\end{array}
$$

Thus, $x = 1000, y = 998$.
Therefore, $n + (-1)^{n} = x + y = 1998$.
When $n$ is even, the solution is $n = 1997$ (contradiction).
When $n$ is odd, the solution is $n = 1999$.