4. Let $X=\{-1,0,1\}, Y=\{-2,-1,0,1,2\}$, and for all elements $x$ in $X$, $x+f(x)$ is even. Then the number of mappings $f$ from $X$ to $Y$ is ( ).
(A) 7
(B) 10
(C) 12
(D) 15.
4. (C).
$x$ and $f(x)$ are both even, or both odd.
When $x=0$, there are three possibilities: $-2, 0, 2$;
When $x=-1, 1$, there are two possibilities each for -1 and 1, making 4 possibilities.
Therefore, the total is $3 \times 4=12$.