C# input has to be 5 digits -
i have question asks user come in pupil number, how can create take 5 digit number. input beingness added object
console.writeline("enter pupil number: "); then
studentobject.studentnumber = int.parse(console.readline()); i've tried using
if (console.readline().length != 5) { //do } else { //do } but won't work, .length says can't convert type int bool. i'm stuck, help please?
you can utilize regular expressions:
string input; { console.writeline("please come in pupil number:"); input = console.readline(); } while (!regex.ismatch(input, @"^\d{5}$")); // <- 5 digits expected // input contains 5 digit string int number = int.parse(number); p.s. in case input should "five digit number, not starting zero" regular look has changed that:
while (!regex.ismatch("12345", @"^[1-9]\d{4}$")); // 5 digits, not zero-starting c#
No comments:
Post a Comment