switch with optional cases (stacked case labels)

this took me a while time to find via MSDN Library or Google. That’s because I didn’t notice it at the bottom of the “switch” explanation on C# (duh!). (And because the fantabulous C# & VB.NET Conversion Pocket Ref doesn’t have an index and I couldn’t find the listing for this in the TOC.) It’s hard when you don’t really know what you are looking for! That is my driving reason for doing the C# for VB programmers talk (at Code Camp this weekend and at DevConnections in a few weeks)

VB lets you put optional cases together as in

Case 3 Or 4 3,4   ‘(duh, I guess I should have gone and looked at one of my many examples of this in my real applications!)
  ‘do something if it’s 3 or 4

C# does it this way

case 3:
case 4:
 //do something if it’s 3 or 4

This seems to be referred to as “stacked case labels”.


  Sign up for my newsletter so you don't miss my conference & Pluralsight course announcements!  

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.