2. Given the function $y=a \cos x+b$ has a maximum value of 1 and a minimum value of $-7$, the maximum value of $a \cos x+b \sin x$ is ( ).
A. 1
B. 3
C. 5
D. 7
2. C.

From the conditions, we know that $y_{\max }=|a|+b=1, y_{\min }=-|a|+b=-7$, so we solve to get $|a|=4, b=3$. Then the maximum value of $a \cos x+b \sin x$ is $\sqrt{a^{2}+b^{2}}=5$.