对象的多个OR? “如果TypeOf控件是ComboBox或TextBox”等

时间:2017-02-27 17:38:17

标签: vb.net

我对编码和VB.net很新。只是想知道是否有更好的方法来做到这一点:

If TypeOf ctl Is ComboBox Or TypeOf ctl Is TextBox Then
' code here
End If

你能做点什么:

If TypeOf ctl is ComboBox or TextBox or... then

End If

1 个答案:

答案 0 :(得分:2)

使用选择案例陈述

    Select Case ctl.GetType
        Case GetType(Button), GetType(PictureBox)
           .... whatever
        Case GetType(Label)
           .... whatever
    End Select

替代答案

使用快速数组也可以。

If {GetType(Button), GetType(PictureBox)}.Contains(ctl.GetType) Then
相关问题