Why does this comparison fails? How do I compare for alternating strings in csharp ?
Static void Main(string[] args)
{
string varFoo = "cat";
if (varFoo != "cat" || varFoo!="duck")
Console.WriteLine("You can enter.");
else
Console.WriteLine("Not allowed.");
Console.ReadLine();
}
Just wanted something as
If(Either cat or a Duck)
// You're not allowed
else
// you are welcomed.
If I understand your comments, “cat” is allowed (and I suppose “duck” is also allowed).
With your last edit (cat and duck can’t enter).
this means :
if
varFoo == "cat": assertion will fail (left part is evaluated, as it is false, right part isn’t evaluated => false).if
varFoo == "duck": assertion will fail (left part is evaluated, it’s true, then right part is evaluated, it’s false => false)this is just boolean way of life :