Tuesday 5 November 2019

Can (a==1 && a==2 && a==3) evaluate to true in C# without multi-threading?



I know it could be done in JavaScript



But is there any possible solution to print "Hurraa" on the condition given below in C# without multi-threading?



if (a==1 && a==2 && a==3) {
Console.WriteLine("Hurraa");
}


Answer



Sure, its the same concept as a few of the javascript answers. You have a side effect in a property getter.



private static int _a;
public static int a { get { return ++_a; } set { _a = value; } }
static void Main(string[] args)
{
a = 0;
if (a == 1 && a == 2 && a == 3)
{

Console.WriteLine("Hurraa");
}
Console.ReadLine();
}

No comments:

Post a Comment

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print &q...