Looks like you need an 'x-or' (one or the other, not both).
As far as I know, there is no x-or operator. You have to combine or (a||b) and not and (!(a&&b))
which would look like
if((a||b)&&!(a&&b)){}
so try this:
bool hasFirstName = !string.IsNullOrEmpty(firstname);
bool hasLastName = !string.IsNullOrEmpty(lastname);
if ((hasFirstName || hasLastName) && !(hasFirstName && hasLastName))
{
}
else
{
}