.Net C# code error that wasted a day of my life

Can you quickly spot the error in this code?

if (GetRandomNumber(1, 20) > 19); // upped this from 17)
        redirout = OtherURL;

You’ll likely think it’s something with a boundary state in the GetRandomNumber method, and sure that’s a good guess, but the actual mistake/error is visible right here, in this code.

If you can’t find it, here’s a hint- we noticed that redirout was being assigned OtherURL a lot.. way more than 1 in 20 times… in fact.. Every time!

The crappy part is it compiled but once your see it, it feels like maybe it shouldn’t compile. I also feel like I was warned about this back 20 years ago.. learning Turbo C. ;p

This actually hurt my business today. No fun, but glad to finally figure it out and get it repaired.

Leave a Reply

Your email address will not be published. Required fields are marked *