您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

如何在 C# 中将输入读取为整数?

2024/11/6 13:02:30发布29次查看
要在c#中将输入读取为整数,请使用convert.toint32()方法。
res = convert.toint32(val);
让我们看看如何 -
convert.toint32 将数字的指定字符串表示形式转换为等效的 32 位有符号整数。
首先,读取控制台输入 -
string val;val = console.readline();
读取后,将其转换为整数。
int res;res = convert.toint32(val);
让我们看一个示例 -
示例 现场演示
using system;using system.collections.generic;class demo { static void main() { string val; int res; console.writeline("input from user: "); val = console.readline(); // convert to integer res = convert.toint32(val); // display the line console.writeline("input = {0}", res); }}
输出input from user:input = 0
以下是输出。输入由用户输入。
input from user: 2input = 2
以上就是如何在 c# 中将输入读取为整数?的详细内容。
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product