M
Matty
Hi,
I'm currently learning c# and am confused why the first example below
doesn't work but the second one does. I'd appreciate any feeback. Thanks.
First example using !=
string input = Console.ReadLine();
if ((input != "0") || (input != "1"))
{
Console.WriteLine("not equal to 0 or 1");
}
else
{
Console.WriteLine("is equal to 0 or 1");
}
Console.ReadLine();
Second example using a single ! followed by ==
string input = Console.ReadLine();
if (!((input == "0") || (input == "1")))
{
Console.WriteLine("not equal to 0 or 1");
}
else
{
Console.WriteLine("is equal to 0 or 1");
}
Console.ReadLine();
I'm currently learning c# and am confused why the first example below
doesn't work but the second one does. I'd appreciate any feeback. Thanks.
First example using !=
string input = Console.ReadLine();
if ((input != "0") || (input != "1"))
{
Console.WriteLine("not equal to 0 or 1");
}
else
{
Console.WriteLine("is equal to 0 or 1");
}
Console.ReadLine();
Second example using a single ! followed by ==
string input = Console.ReadLine();
if (!((input == "0") || (input == "1")))
{
Console.WriteLine("not equal to 0 or 1");
}
else
{
Console.WriteLine("is equal to 0 or 1");
}
Console.ReadLine();