VB.NET study notes (conditional statements)

zhaozj2021-02-16  49

Conditional statements

The condition statement in VB.NET is still the if Then statement and the SELECR CASE statement.

IF THEN statement

The if Then statement is relatively simple, and the same rule is the same.

IF conditional statement example

Public Class Testa

Public Sub New ()

DIM B as Boolean = True

IF b = True Then

'deal with

Else

'deal with

END IF

End Sub

END CLASS

Select Case

The SELECT CASE statement is executed by branch judgment of multiple results of the condition. It is worth noting that the judgment expression of Seleect Case must be calculated as a basic data type (Boolean, Byte, CHAR, DATE, DOUBLE, DECIMAL, INTEGER, LONG, OBJECT, SHORT, SINGLE, and STRING).

VB.NET's CASE block execution cannot be "through" to the next Switch section. This is called "no running" rules. So there is no need to have Break to jump out of the CASE block.

The CASE sentence can be a single variable or a hybrid expression of TO and IS.

SELECT CSAE Example

Public Class Testa

Public Sub New ()

DIM I as INT32 = 100

SELECT CASE I

Case 1, 3, 5, 7

'deal with

Case 8 TO 12

'deal with

Case 13 to 21, 25

'deal with

Case 31 To 35, 39, IS> 50

'deal with

End SELECT

End Sub

END CLASS

转载请注明原文地址:https://www.9cbs.com/read-27045.html

New Post(0)