• Saves Valuable Time
  • Trusted Accuracy for 12 Years
  • 15-Day Money-Back Guarantee

C# Equivalent to VB Select

For simple cases, VB's Select construct can be converted to the C# switch construct.  However, if any of the Case statements include range or non-constant expressions, then the equivalent is an if/else block.

VB C#
'converts to switch:
Select Case x
    Case 0
        ...
    Case 1
        ...
End Select

'converts to if/else:
Select Case x
    Case 1 To 3
        ...
    Case Is < 10, Is > 20, Is = 15
        ...
End Select
//converts to switch:
switch (x)
{
    case 0:
        //...
        break;
    case 1:
        //...
        break;
}

//converts to if/else:
if (x >= 1 && x <= 3)
{
    ...
}
else if ((x < 10) || (x > 20) || (x == 15))
{
    ...
}


Use Instant C# and Instant VB to convert between VB.NET and C#.     

Additional resource: VB.NET and C# Equivalents


Copyright © 1997 – 2017 Tangible Software Solutions Inc.