Dimension of all matrices, commutable with a diagonalizable matrix Let $B \in \mathbb F^{n\times n}$ be a diagonalizable matrix with distinct eigenvalues $\lambda_1...\lambda_s$ of multiplicity $k_1...k_s$ respectively. 
Let $C=\{A \in \mathbb F^{n\times n}: BA=AB\}$.
Show that C is a vector subspace of $\mathbb F^{n\times n}$ of dimension $k^2_1+...+k^2_s$.
I belive that the fact that $BA(v_{\lambda})=AB(v_{\lambda})=A\lambda v = \lambda Av$ will surely lead to an answer, but i'm stuck with no directions.
 A: Let us consider the analogous question for linear operators. Given a diagonalizable operator $T \colon V \rightarrow V$ with eigenvalues $\lambda_1, \ldots, \lambda_s$ of multiplicities $k_1, \ldots, k_s$ respectively, denote by $V_i = \ker(T - \lambda_i \cdot \operatorname{id})$ the corresponding eigenspaces. Consider the subspaces
$$ D = \{ S \in \operatorname{Hom}(V,V) \,\, | \,\, S(V_i) \subseteq V_i \,\,\, \forall 1 \leq i \leq s \}, \\
   C = \{ S \in \operatorname{Hom}(V,V) \,\, | \,\, ST = TS \}. $$
If $S$ commutes with $T$, then each $V_i$ is $S$-invariant so $C \subseteq D$. On the other hand, if $S \in D$ then because $V_i$ are both $T$ and $S$ invariant and $T$ acts on $V_i$ as $\lambda_i \cdot \operatorname{id}$, we have
$$ (ST)|_{V_i} = S|_{V_i} \circ T|_{V_i} = S|_{V_i} \circ (\lambda_i \cdot \operatorname{id})|_{V_i} = (\lambda_i \cdot \operatorname{id})|_{V_i} \circ S|_{V_i} = T|_{V_i} \circ S|_{V_i} = (TS)|_{V_i}. $$
Since $V = \bigoplus_{i=1}^s V_i$, this shows that $TS = ST$ and so $S \in C$ and $C = D$.
Finally, by choosing bases for $V_i$ we see that each $S \in D$ is represented by a block diagonal matrix with blocks of size $\dim V_i = k_i$ which implies that $\dim C = \dim D = \sum_{i=1}^s k_i^2$. 
