How to use case statement in VB.NET
This article will explain in detail how to use the case statement in VB.NET. The editor thinks it is very practical, so I share it for you as a reference. I hope you can get something after reading this article.
VB.NET CASE statement:
Copy the contents to the clipboard program code
Select Case itemc Case 1 Response.Write ("1") Case 2 Response.Write ("2") Case 3 Response.Write ("3") Case 4 Response.Write ("4") Case Else Response.Write ("other") End Select
Switch statement:
Copy the contents to the clipboard program code
Switch (itemc) {case 1: Response.Write ("1"); break; case 2: Response.Write ("2"); break; case 3: Response.Write ("3"); break; case 4: Response.Write ("4"); break; default: Response.Write ("other"); break;}
Note: each branch of switch must end with break (or other jump statement), or it will continue to execute the code of the next branch, but this is illegal in C #, unlike Select Case, as long as one branch is executed, no other branches are executed in Select Case! By the way, each branch of JavaScript's switch statement also requires break statements, but if there is a lack of break statements, there will be no error in JavaScript, and as a result, the code for the rest of the branches will be executed!
Test multiple literals at a time
Copy the contents to the clipboard program code VB.NET CASE statement:
Select Case itemc Case 1,2 Response.Write ("1 or 2") Case 3,4 Response.Write ("3 or 4") Case Else Response.Write ("other") End Select
Switch statement:
Copy the contents to the clipboard program code
Switch (itemc) {case 1: case 2: Response.Write ("1 or 2"); break; case 3: case 4: Response.Write ("3 or 4"); break; default: Response.Write ("other"); break;}
Complex conditions
Copy the contents to the clipboard program code VB.NET CASE statement:
Select Case itemc Case Is