为什么要使用Convert.ToInt32? [英] Why use Convert.ToInt32?
问题描述
因此,我在使用命令提示符计算器时遇到了我不理解的问题.这是我的代码:
静态void Add()
{
int x,y;
Console.Write(输入第一个数字:");
x = Console.Read();
Console.WriteLine(输入第二个数字:");
y = Console.Read();解决方案
Hi <身体>
严重程度
代码
说明
项目
文件
行
抑制状态
错误
CS0029
无法将类型'string'隐式转换为'int'
Expression_Evaluator
D:\ C#Repro \ Winform \ ListViewDemo \ Expression_Evaluator \ Program.cs
16
有效
使用它后,此方法将帮助您将字符串转换为int.有关更多详细信息,请参阅 https://msdn.microsoft.com/en-us/library/sf1aw27b (v = vs.110).aspx
最诚挚的问候,
克里斯汀
So I was working on a command prompt calculator and ran into a problem I don't understand. Here is my code:
static void Add()
{
int x, y;
Console.Write("Enter first number: ");
x = Console.Read();
Console.WriteLine("Enter Second number: ");
y = Console.Read();解决方案Hi Ike Nwaogu,
Convert.ToInt32 Method converts the specified string representation of a number to an equivalent 32-bit signed integer.
Based on your code, if you don't use Convert.ToInt32, there is a build error as following.
Severity
Code
Description
Project
File
Line
Suppression State
Error
CS0029
Cannot implicitly convert type 'string' to 'int'
Expression_Evaluator
D:\C# Repro\Winform\ListViewDemo\Expression_Evaluator\Program.cs
16
Active
After you use it, this method will help you convert string to int. For more details, please refer to https://msdn.microsoft.com/en-us/library/sf1aw27b(v=vs.110).aspx
Best regards,
Kristin
这篇关于为什么要使用Convert.ToInt32?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文