There are k components and n vertices.
Let us assume that number of vertices in different components to be $n1$, $n2$, $n3$, $n4$,... $nk$.
Now, number of edges in each components will be $n1-1$, $n2-1$, $n3-1$, $n4-1$,... $nk-1$. (Since, each component in a forest is a tree, and if no. of vertices in a tree is $i$, then no. of edges in that tree is $i-1$)
Total number of edges = $(n1-1)+(n2-1)+(n3-1)+(n4-1)+... (nk-1)$
$=(n1+n2+n3+n4+...nk)-(1+1+1+1+...' k'times )$
$=n-k$ (Since, $n1+n2+n3+n4+...nk=n$)
So, option D is correct.