我收到以下错误 Operator '==' cannot be applied to operands of type 'int' and 'string' password == "55555" is marked as an error
I get the following error Operator '==' cannot be applied to operands of type 'int' and 'string' password == "55555" is marked as an error
namespace if4
{
class Program
{
static void Main(string[] args)
{
string username;
int password = new int();
string userValue;
userValue = Console.ReadLine();
Console.WriteLine("Enter your username:");
userValue = Console.ReadLine();
Console.WriteLine("Enter your password: ");
if (username == "code" && password == "55555")
{
Console.WriteLine("Access allowed! ");
Console.ReadLine();
}
else
{
Console.WriteLine("Access denied! ");
}
Console.ReadLine();
}
}
}
您不能将 int 与 string 进行比较,您需要将 password 声明为 string,而不是 int,或者将“55555”转换为 int,或者 password == 555555
namespace if4
{
class Program
{
static void Main(string[] args)
{
string username;
int password = new int();
string userValue;
userValue = Console.ReadLine();
Console.WriteLine("Enter your username:");
userValue = Console.ReadLine();
Console.WriteLine("Enter your password: ");
if (username == "code" && password == "55555")
{
Console.WriteLine("Access allowed! ");
Console.ReadLine();
}
else
{
Console.WriteLine("Access denied! ");
}
Console.ReadLine();
}
}
}
您不能将 int 与 string 进行比较,您需要将 password 声明为 string,而不是 int,或者将“55555”转换为 int,或者 password == 555555