I have this: public void InfoAssignment(){    //MessageBox.Show(firstName = firstNameBox.Text);    firstName = firstNameBox.Text;    lastName = lastNameBox.Text;    phoneNumber = phoneBox.Text;    address = addressBox.Text;    //Check for text in firstNameBox    if (!String.IsNullOrWhiteSpace(firstName))    {        firstName = firstNameBox.Text;    }    else    {        MessageBox.Show(Please enter a first name);        return;    }    if (!String.IsNullOrWhiteSpace(lastName))    {        lastName = lastNameBox.Text;    }    else    {        MessageBox.Show(Please enter a last name);        return;    }    if(!String.IsNullOrWhiteSpace(phoneNumber))    {        phoneNumber = phoneBox.Text;    }    else    {        MessageBox.Show(Please enter a phone number);        return;    }    if (!String.IsNullOrWhiteSpace(address))    {        address = addressBox.Text;    }    else    {        MessageBox.Show(Please enter a phone number);        return;    }    //firstName = firstNameBox.Text;    //lastName = lastNameBox.Text;}It does what I need it to do but obviously this is basically repeating the same thing with only minor variations. I'm thinking there has to be a better way of which I'm unaware. Is there?
Extracting first name, last name, phone number, and address from a form
c#;validation;form
Here you go.Pass the variables by reference and let the method update them if the input is valid.Do processing if all the inputs are valid.EDIT: I needed to change the method name from ValidateInput to CopyToVariableWithValidation because the former fails to have a good name to represent it's function.private bool CopyToVariableWithValidation(TextBox textBox, string inputFriendlyName, ref string variableToCopyContent){    if (string.IsNullOrWhiteSpace(textBox.Text))    {        MessageBox.Show(Please enter a  + inputFriendlyName);        return false;    }    variableToCopyContent = textBox.Text;    return true;}public void InfoAssignment(){    if    (        CopyToVariableWithValidation(firstNameBox, First Name, ref firstName) &&        CopyToVariableWithValidation(lastNameBox, Last Name, ref lastName) &&        CopyToVariableWithValidation(phoneBox, Phone Number, ref phoneNumber) &&        CopyToVariableWithValidation(addressBox, Address, ref address)    )    {        // Input is valid. Do more processing here.    }}