나는 Lynda의 기본 교육 자습서를 따라하고 예제를 약간 변경하려고 C#을 배우려고합니다.'string'유형을 암시 적으로 'int'로 변환 할 수 없습니다. (CS0029)
Google에서 해결책을 찾을 수 없다는 오류가 발생합니다.
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'(CS0029)
코드로 유형 '문자열을'변환 할 수 없습니다. 내 함수가 int를 얻고 있고, 콘솔에서 얻고 자하는 arg 또한 int이다. 컴파일러가 말하는 문자열은 어디에 있습니까? :)
** [공식 MSDN 설명서] (http://msdn.microsoft.com/en-us/library/system.console.readline%28v=vs.110%29.aspx)를 참조하십시오 ** 'Console.ReadLine' **, 문자열 ** (int가 아닌) **을 반환합니다. –
@marc_s, 맞습니다. 죄송합니다. 다시는 발생하지 않습니다. – SilenceIsGolden