16

在 CI 中可以分配default给一些现有的switch条目:

switch(c) {

default :
case 1:

       break;

case 2 :


      break;   

}

VB的select语句中是否有类似的可能性?

4

2 回答 2

25

use case Else,它与 c 语法的默认值相同:

Select [ Case ] testexpression
    [ Case expressionlist
        [ statements ] ]
    [ Case Else
        [ elsestatements ] ]
End Select

例如

creamcake = TextBox1.Text

Select Case creamcake

Case "Eaten"
DietState = "Diet Ruined"
Case "Not Eaten"
DietState = "Diet Not Ruined"
Case Else
DietState = "Didn't check"
End Select

如果您想分配多个案例,那么示例

Select Case agerange

Case 16 To 21
MsgBox “Still Young”
Case 50 To 64
MsgBox “Start Lying”

End Select
于 2012-12-05T09:53:03.117 回答
1
Select Object.Name.ToString()
    Case "Name1"
        'Do something
    Case "Name2"
        'Do something else
    Case Else
        'Do the default action
End Select

This question is the exact opposite of VB.NET Select...Case Statement Equivalent in C#

于 2012-12-05T09:51:31.060 回答