我在C#密码控件中收到此错误:
无法将类型'string'隐式转换为'int'
请您帮忙?
int newPassPP2 = 19;
Console.WriteLine("Enter the Password : ");
int readNewPassword = int.Parse(Console.ReadLine());
int writeNewPassword(int newNumOne)
{
return newNumOne == readNewPassword ? "Number is true" : "Number is false";
}
Console.WriteLine(writeNewPassword(newPassPP2));
此代码行上发生错误:
return newNumOne == readNewPassword ? "Number is true" : "Number is false";
谢谢
答案 0 :(得分:2)
您需要从本地方法返回一个字符串
...
string writeNewPassword(int newNumOne)
{
return newNumOne == readNewPassword ? "Number is true" : "Number is false";
}
Console.WriteLine(writeNewPassword(newPassPP2));
...
答案 1 :(得分:1)
您的方法返回类型为 int
,现在将其更改为 string
的数据类型,
private string myMethod()