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

bookChallenge: Robust Input Handling

Tarefa

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.

Solução

Tudo estava claro?

Como podemos melhorá-lo?

Obrigado pelo seu feedback!

Seção 3. Capítulo 6
single

single

Pergunte à IA

expand

Pergunte à IA

ChatGPT

Pergunte o que quiser ou experimente uma das perguntas sugeridas para iniciar nosso bate-papo

Suggested prompts:

Can you explain this in simpler terms?

What are the main benefits or drawbacks?

Can you give me a real-world example?

close

bookChallenge: Robust Input Handling

Deslize para mostrar o menu

Tarefa

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.

Solução

Switch to desktopMude para o desktop para praticar no mundo realContinue de onde você está usando uma das opções abaixo
Tudo estava claro?

Como podemos melhorá-lo?

Obrigado pelo seu feedback!

Seção 3. Capítulo 6
single

single

some-alt