Nugget: Little compiler optimisation
Found this little C# compiler optimisation which is really cool. Here is the start code:
int y = 0;
int x = 10;
if (x * 0 == 0)
{
y = 123;
}
Console.WriteLine(y);
If you know a bit of math, anything multiplied by 0 always equals 0 (line 4). So the compiler optimises that out, and then because x is never used, it’s also optimised out, and you end up with:
int y = 0;
if (0 == 0)
{
y = 123;
}
Console.WriteLine(y);
So very smart! 😊