Challenge: Robust Input Handling
Uppgift
Swipe to start coding
Write a method for a reservation system that validates and safely parses user input for a reservation date and the number of guests. The method should use TryParse for parsing and ensure the number of guests is a positive integer.
- Parse the
dateInputstring to aDateTimevalue usingDateTime.TryParse. - Parse the
guestsInputstring to anintvalue usingint.TryParse. - Return
trueonly if both parsing operations are successful and the number of guests is greater than zero. - Set the
reservationDateandnumberOfGuestsout parameters to the parsed values if valid; otherwise, set them to their default values.
Lösning
Var allt tydligt?
Tack för dina kommentarer!
Avsnitt 3. Kapitel 6
single
Fråga AI
Fråga AI
Fråga vad du vill eller prova någon av de föreslagna frågorna för att starta vårt samtal
Fantastiskt!
Completion betyg förbättrat till 4.17
Challenge: Robust Input Handling
Svep för att visa menyn
Uppgift
Swipe to start coding
Write a method for a reservation system that validates and safely parses user input for a reservation date and the number of guests. The method should use TryParse for parsing and ensure the number of guests is a positive integer.
- Parse the
dateInputstring to aDateTimevalue usingDateTime.TryParse. - Parse the
guestsInputstring to anintvalue usingint.TryParse. - Return
trueonly if both parsing operations are successful and the number of guests is greater than zero. - Set the
reservationDateandnumberOfGuestsout parameters to the parsed values if valid; otherwise, set them to their default values.
Lösning
Var allt tydligt?
Tack för dina kommentarer!
Avsnitt 3. Kapitel 6
single