For the function
$$
f(x)=\left\{\begin{array}{ll}
x^{2}+b x+c & x \geqslant 0 ; \\
-2, & x<0,
\end{array}\right.
$$

it is given that $f(4)=f(0), f(1)=-1$. Then the number of solutions to the equation $f(x)=x$ is ( ).
(A) 0
(B) 1
(C) 2
(D) 3
6. D.
$$
\begin{array}{l}
\text { Given } f(4)=f(0), f(1)=-1 \\
\Rightarrow 16+4 b+c=c, 1+b+c=-1 \\
\Rightarrow b=-4, c=2 . \\
\text { Therefore, } f(x)=\left\{\begin{array}{ll}
x^{2}-4 x+2, & x \geqslant 0 ; \\
-2, & x<0 .
\end{array}\right.
\end{array}
$$

Its graph is shown in Figure 4, with a total of 3 solutions.