Challenge: Robust Input Handling
Aufgabe
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ösung
War alles klar?
Danke für Ihr Feedback!
Abschnitt 3. Kapitel 6
single
Fragen Sie AI
Fragen Sie AI
Fragen Sie alles oder probieren Sie eine der vorgeschlagenen Fragen, um unser Gespräch zu beginnen
Großartig!
Completion Rate verbessert auf 4.17
Challenge: Robust Input Handling
Swipe um das Menü anzuzeigen
Aufgabe
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ösung
War alles klar?
Danke für Ihr Feedback!
Abschnitt 3. Kapitel 6
single