Challenge: Robust Input Handling
Tâche
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.
Solution
Tout était clair ?
Merci pour vos commentaires !
Section 3. Chapitre 6
single
Demandez à l'IA
Demandez à l'IA
Posez n'importe quelle question ou essayez l'une des questions suggérées pour commencer notre discussion
Génial!
Completion taux amélioré à 4.17
Challenge: Robust Input Handling
Glissez pour afficher le menu
Tâche
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.
Solution
Tout était clair ?
Merci pour vos commentaires !
Section 3. Chapitre 6
single