我对我的方式通过以下从琳达的基本培训教程,并试图把他们的例子一些改变学习C#。无法隐式转换类型“字符串”到“廉政”(CS0029)
我卡上,我找不到在谷歌的解决方案的错误。
无法隐式转换类型 '字符串' 到 '廉政'(CS0029)
代码:
namespace l2
{
class Program
{
public static void Main(string[] args)
{
int arg;
arg = Console.ReadLine();
int result1;
result1 = formula(arg);
Console.WriteLine("the result is {0}",result1);
Console.ReadKey();
}
static int formula (int theVal){
return (theVal * 2 + 15);
}
}
}
我真的不明白,为什么我得到这个错误。我的函数获得一个int,我想从控制台获得的arg也是一个int。编译器正在讨论的字符串在哪里? :)
如果你只想**咨询【官方MSDN文档(http://msdn.microsoft.com/en-us/library/system.console.readline%28v=vs.110%29.aspx)上'Console.ReadLine' **,你会看到它返回一个** **字符串(不是'int').... – 2014-10-03 18:26:23
@marc_s,这是正确的。对不起,不会再发生。 – SilenceIsGolden 2014-10-03 18:30:52