Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use case statement in VB.NET

2025-01-15 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

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

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report