How to read an integer using console.readline()?

前端 未结 4 1451
既然无缘
既然无缘 2020-12-22 13:50

I\'m a beginner who is learning .NET.

I tried parsing my integer in console readline but it shows a format exception.

My code:

using System;         


        
4条回答
  •  粉色の甜心
    2020-12-22 14:32

    Your code is absolutely correct but your input may not be integer so you are getting the errors. Try to use the conversion code in try catch block or use int.TryParse instead.

提交回复
热议问题