Oh, 2 things: 1) It's a console app 2) I know that it's in Denmark, but it's actually It does not matter, some example of this is asking for input text and variables do not matter.
OK, consider this simple input: it can actually be any kind of input question.
console.light line ("kundanemar: (kun hele taaladadad)"); String input Knr = console. Redline (); Kundenummur = Convert. ToInt16 (inputKnr);
Now, is customer type something wrong? Try one such as a letter & amp; The catch ensures that the application does not break, but this is not the solution that I want. I want to say that you did it wrong, try again beautiful classic right?
But what is the best way to solve this solution? I have thought about it:
bool fanget Kundenummer = true; While (Fenget Kundanmumer) {console. Virline ("Whom ARI Contemporter: (Kun Hale Rastard)"); String input Knr = console. Redline (); Try {kundenummer = Convert.ToInt16 (inputKnr); FangetKundenummer = false; } Hold {console} WrightLine ("Fejl. Prøv igen"); }}
But this does not seem to be the right way to do this.
Besides, just to tell, this small application I'm playing with 4 input questions in a row . This means it's 4 times bad (while loop).
You can also write a function. Something like this (there is no reason to do it correctly, to clarify its concept):
Fixed zero probe input () {{console.writeline ("question") Try; Input = console Readline (); Kundenumur = Convert.TiInnt16 (Input)} Hold {Console. WrightLine ("wrong, finish it"); VerifyInput (); // start full function}}
But you have to type a function for each input question, even if they can ask for it! (I.e. maybe all asking for an integer, but with a different question and variable)
It does not seem much better than the time () solution.
Anybody cunning thoughts?
Use and equivalent to other numerical types. All this indicates success or failure to parse boolean results, and takes a out
parameter set on the result of parsing (or 0 in case of failure). In your case, you want to wrap the call in a method:
Static Int16 PromptForInt16 {String Prompt} {While (true) {Console.Write (hint); Int16 results; If (Int16.TryParse (console .readlined (), outcomes)) return result; } Console.WriteLine ("Sorry, invalid number entered. Try again."); }}