C#/C# Question
Expert: Srini Nagarajan - 5/3/2005
QuestionHello Srini,
I am currently learning C# on my own. I made a C# Console database program that interacts with SQL server 2000 database. The program is simple, just add new student, delete,update,search and count records. I have made a main menu with choice(1-7) and I use the following statement to accept the choice from the user:
int choice = int.Parse(Console.ReadLine());
the problem here is that as long as I input numeric digits; the program works fine but when I mistakenly put a letter(a-z) as an input; the program gives an Format Exception. I tried a lot to get rid of this problem, but in vain.
I will really appreciate if you could assist me in accomplishing this.
Thanks
Jehan
AnswerHi
before doing this "int.Parse(Console.ReadLine())"
use typeof function to find whether its a Integer if not you can pop different message
Here is the microsoft site gives you some sample
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/csref/html/vclr...
Happy Programming!!
-Srini