我正在使用 c# 开发一个简单的密码存储控制台应用程序。
我在询问用户是否想从那时起屏蔽所有密码条目的部分上遇到了一些问题。
这是代码部分:
bool tryagain = true;
while(tryagain == true)
{
Console.WriteLine("Would you like to mask all other password entiries?(Y,N)");
string input = Console.ReadLine();
if (input == "y" | input == "Y")
//Something wrong, always passes to Your awnser was invalid
{
maskpass = true;
tryagain = false;
}
if (input == "n" | input == "N")
{
maskpass = false;
tryagain = false;
}
else
{
Console.WriteLine("Your awnser was invalid, would you like to try again?");
string yesno = Console.ReadLine();
if (yesno == "y" | yesno == "Y")
{
tryagain = true;
}
if (yesno == "n" | yesno == "N")
{
Environment.Exit(0);
}
}
}
问题是当我运行代码时,它总是运行到 else 语句。
我确定这个错误很简单,我只是无知,但有人知道这里发生了什么吗?