VB.Net - Select Case语句
Select Case语句允许根据值列表测试变量的相等性。 每个值称为大小写,并且为每个选择大小检查打开的变量。
语法:
Select [ Case ] expression
[ Case expressionlist
[ statements ] ]
[ Case Else
[ elsestatements ] ]
End Select
expression: is an expression that must evaluate to any of the elementary data type in VB.Net, i.e., Boolean, Byte, Char, Date, Double, Decimal, Integer, Long, Object, SByte, Short, Single, String, UInteger, ULong, and UShort.是必须求值到VB.Net中的任何基本数据类型的表达式,即布尔值,字节,字符,日期,双精度,小数,整数,长整型,对象,SByte,短,单,字符串,UInteger, ULong和UShort。
expressionlist: List of expression clauses representing match values forexpression. Multiple expression clauses are separated by commas.表达式子句表示表达式的匹配值的列表。用逗号分隔多个表达式子句。
statements: statements following Case that run if the select expression matches any clause in expressionlist.语句如果select表达式匹配expressionlist中的任何子句,则运行的案例。
elsestatements: statements following Case Else that run if the select expression does not match any clause in the expressionlist of any of the Case statements.如果select表达式与任何Case语句的expression列表中的任何子句不匹配,则运行Case Else后的语句。
流程图:
示例:
Module decisions
Sub Main()
'local variable definition
Dim grade As Char
grade = "B"
Select grade
Case "A"
Console.WriteLine("Excellent!")
Case "B", "C"
Console.WriteLine("Well done")
Case "D"
Console.WriteLine("You passed")
Case "F"
Console.WriteLine("Better try again")
Case Else
Console.WriteLine("Invalid grade")
End Select
Console.WriteLine("Your grade is {0}", grade)
Console.ReadLine()
End Sub
End Module
Well done
Your grade is B
更多建议: