Hint First, note that the answer clearly depends on the matrix $D$. If $D$ is a multiple $\lambda I_n$ of the identity matrix, every $n \times n$ matrix $C$ satisfies $CD = DC$ (we say that $C$ commutes with $D$). On the other hand, one can show that the multiples $\lambda I_n$ are the only matrices that commute will all matrices.
We can approach the problem naively and write out the equation $CD = DC$ in entries: Taking the $(i, j)$ entry of each side gives
$$\sum_{k = 1}^n c_{ik} d_{kj} = \sum_{k = 1}^n d_{ik} c_{kj} .$$
This is a rather complicated quadratic relation, and, indeed if $D$ were a general matrix, this wouldn't be a very efficient approach---but since in our case $D$ is diagonal, so $d_{kj}$ is zero unless $k = j$. If we substitute these relations into the equation, it simplifies to
$$c_{ij} d_{jj} = d_{ii} c_{ij} .$$
So, if $d_{ii} = d_{jj}$, then $c_{ij}$ can assume any value, but if $d_{ii} \neq d_{jj}$, we must have $c_{ij} = 0$.