Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Apprendre Challenge: Robust Input Handling | Validating Input and Safe Parsing
C# Exceptions and Error Handling Practice

bookChallenge: 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 dateInput string to a DateTime value using DateTime.TryParse.
  • Parse the guestsInput string to an int value using int.TryParse.
  • Return true only if both parsing operations are successful and the number of guests is greater than zero.
  • Set the reservationDate and numberOfGuests out parameters to the parsed values if valid; otherwise, set them to their default values.

Solution

Tout était clair ?

Comment pouvons-nous l'améliorer ?

Merci pour vos commentaires !

Section 3. Chapitre 6
single

single

Demandez à l'IA

expand

Demandez à l'IA

ChatGPT

Posez n'importe quelle question ou essayez l'une des questions suggérées pour commencer notre discussion

close

bookChallenge: 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 dateInput string to a DateTime value using DateTime.TryParse.
  • Parse the guestsInput string to an int value using int.TryParse.
  • Return true only if both parsing operations are successful and the number of guests is greater than zero.
  • Set the reservationDate and numberOfGuests out parameters to the parsed values if valid; otherwise, set them to their default values.

Solution

Switch to desktopPassez à un bureau pour une pratique réelleContinuez d'où vous êtes en utilisant l'une des options ci-dessous
Tout était clair ?

Comment pouvons-nous l'améliorer ?

Merci pour vos commentaires !

Section 3. Chapitre 6
single

single

some-alt