我求助了 [英] I wneed help
问题描述
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace someting2
{
class Program
{
static void Main(string[] args)
{
//Varibles
int num;
int num2;
//Commands
Console.WriteLine("Type 2 Numbers");
Console.Write("Number 1");
Console.ReadLine(num);
Console.Write("Number 2");
Console.ReadLine(num2);
if (num < num2)
{
Console.WriteLine("u suck");
}
else
Console.WriteLine("U RULE!! YHE");
}
}
}
严重程度 代码
描述 项目
文件 行
抑制状态
错误 CS0165
使用未分配的局部变量'num' someting2
C:\ Users\Liam\source \repos\someting2 \someting2 \Program.cs
24 有效
错误 CS1501
方法'ReadLin没有重载e'需要1个参数
someting2 C:\ Users\Liam \ thesource \repos\someting2 \someting2 \Program.cs
24 有效
错误 CS0165
使用未分配的局部变量'num2' someting2
C:\ Users\Liam\source \repos\someting2 \someting2 \Program.cs
27 有效
错误 CS1501
方法'ReadLine'没有重载需要1个参数
someting2 跨度> C:\Users\Liam\source\\ repos\someting2 \someting2 \Program.cs
27 有效
i想让你在控制台输入2号码,如果num低于num 2,你会说你很糟糕! plz help
Severity Code
Description Project
File Line
Suppression State
Error CS0165
Use of unassigned local variable 'num' someting2
C:\Users\Liam\source\repos\someting2\someting2\Program.cs
24 Active
Error CS1501
No overload for method 'ReadLine' takes 1 arguments
someting2 C:\Users\Liam\source\repos\someting2\someting2\Program.cs
24 Active
Error CS0165
Use of unassigned local variable 'num2' someting2
C:\Users\Liam\source\repos\someting2\someting2\Program.cs
27 Active
Error CS1501
No overload for method 'ReadLine' takes 1 arguments
someting2 C:\Users\Liam\source\repos\someting2\someting2\Program.cs
27 Active
i want to make so u type 2 number in console and if num is lower then num 2 it will say u suck! plz help
推荐答案
Console.ReadLine不带任何参数(括号中没有任何内容)。它返回一个字符串,你必须将其转换为整数。
Console.ReadLine does not take any arguments (nothing in the parentheses). It returns a string, which you must convert to an integer.
这是一个简单的修复。
Console.Write("Number 1");
string snum = Console.ReadLine();
num = Convert.ToInt32(snum);
Console.Write("Number 2");
string snum2 = Console.ReadLine();
num2 = Convert.ToInt32(snum2);
稍微复杂一点的更好方法是使用TryParse(你可以谷歌吧)如果你有兴趣)。
A better way that is slightly more complicated would be to use TryParse (you can Google it if you're interested).
这篇关于我求助了的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!