4. Given $x+y+x y+1=0, x^{2} y+x y^{2}+2=0$. Then $(x-y)^{2}$ equals ( ).
(A) 1 or 8
(B) 0 or 9
(C) 4 or 8
(D) 4 or 9
4.B

Translate the text above into English, please retain the original text's line breaks and format, and output the translation result directly.