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
|
60a6e645-d202-4533-9ff1-85415c8685ff|0|.0
Views: 2107
Tags: vb.net
VB.Net