lundi 8 octobre 2018

Using try-catch instead of if statement

Currently learning c#. Is there any way I could use a try-catch block on the code below instead of an if statement to validate user input?

string carID = txtCar.Text;
if (carID != "")
{
    car1.car = carID;
}
else
{
    MessageBox.Show("Please enter a car id e.g: ford");
}

Aucun commentaire:

Enregistrer un commentaire