C# Compared—Select Case

Microsoft .NET Framework, ASP.NET, Visual C# (CSharp, C Sharp, C-Sharp) Developer Training, Visual Studio


Jump to: navigation, search
CSharp-Online.NET:Articles
C# Articles

C# Compared to Other Languages

© 2005 C. Gunnerson, et al.

Select Case

The switch statement in C# does the same thing as Select Case. This VB code

Select Case x
   Case 1
      Func1
   Case 2
      Func2
   Case 3
      Func2
   Case Else
      Func3
End Select

can be rewritten as:

switch (x)
{
   case 1:
      Func1();
      break;
   case 2:
   case 3:
      Func2();
      break;
   default:
      Func3();
      break;
}


Previous_Page_.gif Next_Page_.gif


Personal tools