c# - Validating User Input and Type -


I have designed an input validation loop in C #, and I want to be able to check it for the correct input format. I'm not sure, but I think that my designed loop is not checking the type of input, just the character that has been entered. I know that I can use an effort-block, but should you not use exceptions only for extraordinary situations? This is not an extraordinary situation, because I hope the user will enter the wrong value.

Question:

Is there a way to give it a new look, so that it is a valid input type Also checks?

Code:

  do {console.write ("Do you want to enter another complex number?: (Y or N) "); Feedback = char.Parse (Console.ReadLine ()); Reaction = char.ToUpper (feedback); If (feedback! = 'Y' and feedback! = 'N') console.light line ("You must answer Y or N!"); } While (feedback! = 'Y' and feedback! = 'N');  

Good:

reads the next line Characters from standard input stream

Then your data will be of type.

You can only do another check to check that the return length is 1, so you know that you have the correct format input. You can actually enter char.Parse < / Code> is not required because the elements of the string are of char .


Comments

Popular posts from this blog

c# - How to capture HTTP packet with SharpPcap -

jquery - SimpleModal Confirm fails to submit form -

php - Multiple Select with Explode: only returns the word "Array" -