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

plot - Remove Objects from Legend When You Have Also Used Fit, Matlab -

java - Why does my date parsing return a weird date? -

Need help in packaging app using TideSDK on Windows -