S
StudiousStudent
Guest
I'm a beginner at c# and any help will be appreciated.
Essentially the user is asked to input the SecurityCode which has been {get, set,} in the Cars class. The information for this Cars class is stored in a txt file and loaded into the console app.
static List<Car> Cars= new List<Car>(); //list containing the cars
The code I used to input the cars security code and find it's index:
Console.WriteLine("\nPlease enter the SecurityCode of the car you wish to delete\n");
var securityCode = int.Parse(Console.ReadLine());
Car delete = Cars.Find(cr => cr.SecurityCode == securityCode);
int index = Cars.IndexOf(delete);
Cars.RemoveAt(index); //Deletes the car
Cars.CarsNumber--; //Decrements the car count
This all works fine.
How can I validate this so that the console won't crash when the user inputs the wrong SecurityCode?
Umar Arif
Continue reading...
Essentially the user is asked to input the SecurityCode which has been {get, set,} in the Cars class. The information for this Cars class is stored in a txt file and loaded into the console app.
static List<Car> Cars= new List<Car>(); //list containing the cars
The code I used to input the cars security code and find it's index:
Console.WriteLine("\nPlease enter the SecurityCode of the car you wish to delete\n");
var securityCode = int.Parse(Console.ReadLine());
Car delete = Cars.Find(cr => cr.SecurityCode == securityCode);
int index = Cars.IndexOf(delete);
Cars.RemoveAt(index); //Deletes the car
Cars.CarsNumber--; //Decrements the car count
This all works fine.
How can I validate this so that the console won't crash when the user inputs the wrong SecurityCode?
Umar Arif
Continue reading...