Switch statement equivalent in VB.Net

by Viper 29. April 2009 03:33

I have been primarily a C/C++ developer and then moved on to C#. I have done some VB and VB.Net development in the past but not very actively. For last few months I have been involved in lot of VB.Net projects. Every now and then I run into situations where I know how something will be done in C# but not sure how to do it in VB.Net. I mean what will be syntax or statements used in VB.Net that are equivalent to same actions in C#. Yesterday one of my co-workers asked me "What is equivalent of C# Switch statement in VB.Net?". Since I was doing VB.Net development for a prototype project, I quickly answered him "Select Case is equivalent to Switch statement". I thought I will quickly publish this small not showing how Select Case is used in VB.Net.

For example I want to take different action based on what item has been selected in a combo box in my winforms application.

C#
switch(myCombo.SelectedIndex)
{
  case 0: do1(); break;
  case 1: do2(); break;
  case 2: do3(); break;
  default: doNothing(); break;
}
VB.Net
Select Case(myCombo.SelectedIndex)
 Case 0		do1()
 Case 1		do2()
 Case 2		do3()
 Case Else	doNothing()
End Select

Views: 2107

Tags:

VB.Net

Comments

9/26/2009 12:43:53 AM #

Pi

Select Case

Pi United States

10/19/2009 11:43:33 AM #

cash loans

I guess there's always an easier way ...

cash loans United States

Add comment


(Will show your Gravatar icon)

  Country flag

biuquote
  • Comment
  • Preview
Loading



Powered by BlogEngine.NET 1.5.1.7
Theme by Naveen Kohli