Example 2 (Zhejiang, 2008) If $\cos \alpha+2 \sin \alpha=-\sqrt{5}$, then $\tan \alpha=(\quad)$
A. $\frac{1}{2}$
B. 2
C. $-\frac{1}{2}$
D. -2
By the Cauchy-Schwarz inequality, we have:
$$(\cos \alpha+2 \sin \alpha)^{2} \leqslant\left(1^{2}+2^{2}\right)\left(\cos ^{2} \alpha+\sin ^{2} \alpha\right)=$$

Given that $(\cos \alpha+2 \sin \alpha)^{2}=5$, we have $5 \leqslant 5$, which means the equality in the above inequality (1) holds. Therefore, by the condition for equality in the Cauchy-Schwarz inequality, we have $\frac{1}{\cos \alpha}=\frac{2}{\sin \alpha}$, so $\tan \alpha=2$. Hence, the correct choice is B.