console.readline仅返回字符串值??? [英] console.readline only returns string value???

查看:266
本文介绍了console.readline仅返回字符串值???的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在控制台应用程序内部,我希望用户输入数字,但由于console.readline()仅返回字符串值,因此出现错误.如何在不使用readline方法的情况下从用户获取整数输入?

inside a console application i want the user to input a number but since console.readline() only returns string value i get an error.how can i get the integer input from user without using readline method??

推荐答案

使用Convert方法将您的字符串输入转换为整数.
Use the Convert method to convert your string input to an integer.


使用int.TryParse,以便检查它是否为数字,而不会炸毁您的应用程序.
Use int.TryParse so you can check if it''s a number without your app blowing up.


这篇关于console.readline仅返回字符串值???的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆