Short circuiting in .NET

Last week revealed an interesting difference between C# and VB.NET. C# operators like “and” (&&) and “or” (||) do it automatically. The VB.NET operators “And” and “Or” don’t do this by default. So if you use these, all the conditions are evaluated, regardless of whether or not that’s necessary.

In the .NET 2.0 Framework, instead of making these operators work like the C# ones, VB.NET added two new keywords: AndAlso and OrElse.

It’s good that VB.NET has the facility, I just don’t like the implementation.  It’s another reason to prefer C# at the very least.

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.