Girl parts boy parts

What age is appropriate to discuss the difference between boys and girls to your kids? My daughter had some friends over playing. One of which was a boy. I didn't mind that he was over because they were mostly outside. But he stuck around after the little girls left and ended up asking if he could spend the night. I told my daughter, who is 5 and he's 7, no because she can't have sleep overs with little boys. They were playing with her toys and he says "do you want to play mommy and daddy?" I got weird vibes and mommy instinct kicked in and I told him that he needed to have his parents come get him now. The entire time he was here, even when the other girls were here, I never allowed them in the bedroom, they were restricted to the back yard. But after he left my daughter got upset and didn't understand why he couldn't stay. I froze and ended up jusy saying that boys and girls are different and it's not appropriate for him to stay the night. Anyone else have to explain boy parts and girl parts to their kids at a young age? How'd you do it?