Select Case True
This syntax is often used instead of an If...ElseIf
statement. Some people find it a little easier to read. For example:
Select Case True Case testVariable < 0 Console.Write("You must supply a positive value.") Case testVariable > 10 Console.Write("Please enter a number from 0-10.") Case True Call DoWork(testVariable)End Select
The answer is that yes, this still works in VB.NET. Just take care with when you use it, because it's not a "standard programming construct" and may be unfamiliar to people that have to maintain your code in the future.
I'm not sure how this construct offers any advantages over the following:
If testVariable < 0 Then Console.Write("You must supply a positive value.")ElseIf testVariable > 10 Then Console.Write("Please enter a number less than 10.")Else Call DoWork(testVariable)End If
The above structure is short-circuiting, and I don't have to try to work out what it does as it's a standard construct.
Others have already answered that actual question, but I just want to chime in that I use this construct fairly frequently. I think it's often the most readable way of simultaneously testing two boolean conditions:
Dim A As BooleanDim B As Boolean''do stuff to set values of A and B'Select Case True Case A And B 'something Case A And Not B 'something else Case Not A And B 'you get the picture Case Else '...End Select
I admit that part of why I find it easily readable is that I do use it, and that I do recall having to parse it the first time I saw it--but once successfully parsed, my reaction was "That's brilliant!"