c# - Error handling of user input in a List<int> -


i have following code:

       list<int> moneys = new list<int>();        console.writeline("please enter cost of choice");        int money = int.parse(console.readline());        moneys.add(money); 

from if enter text program stops working , unhandled exception message appears. wondering how handle exception, if possible program doesn't stop working?

you should use tryparse method. not throw exception if input not valid. this

int money; if(int.tryparse(console.readline(), out money))    moneys.add(money); 

Comments

Popular posts from this blog

image - ClassNotFoundException when add a prebuilt apk into system.img in android -

I need to import mysql 5.1 to 5.5? -

Java, Hibernate, MySQL - store UTC date-time -