This is where 'Yort' praises, rants, raves and otherwise talks nonsense about Microsoft .NET and Visual Studio. Or anything else related to software development or Microsoft that he feels like throwing in. It's his blog after all...

Sunday, November 01, 2009

Shorten Your If’s By Avoiding ‘Or’

I’m not suggesting there’s necessarily a better language syntax or that we need one, but I find this annoying;

Now I know what you’re thinking, there’s multiple ways the compiler could interpret my use of or (||) in that scenario, but the point is this is a common type of statement to write and it’s unnecessarily verbose – especially if you have meaningful variable and type names which is something that should be encouraged.

Some of you are probably also thinking I should have used switch, which is fine some of the time but still takes up quite a lot room on the screen and isn’t really appropriate when your conditional has only the ‘true’ condition for one set of values.

What we really need is something equivalent to the ‘In’ keyword in t-sql, i.e