Checking if user input is an integer in c# -
this question has answer here:
- c# testing see if string integer? 9 answers
so i'm making little text game, , need user enter integer when asks grid size. , if integer isn't entered want question asked again.
right have:
console.writeline("enter grid size."); int gridsize = int.parse(console.readline());
i need way check if input integer, , ask again if it's not. thanks
you can use tryparse:
var input = 0; if(int.tryparse(console.readline(), out input) { }
Comments
Post a Comment