我正在尝试使用变量调用集合中的属性。我有多个属性,我不想使用 case 语句来获取信息。这是代码示例
Sub Main()
MessageBox("Total: " & GetNum("Total","1"))
MessageBox("Night: " & GetNum("Night","1"))
End Sub
Private Function GetNum(ByVal pstrProp AS String, ByVal pstrNum AS String) As Double
Dim lobjProperties as New Properties
'this is where the issue is
return lobjProperties."pstrProp"(pstrNum)
End Function
Public Class Properties
Public ReadOnly Property Total(ByVal pstrNum As String) As Double
Get
Select Case pstrNum
Case "1"
Return 48
Case "2"
Return 30
Case Else
Return 0
End Select
End Get
End Property
Public ReadOnly Property Night(ByVal pstrNum As String) As Double
Get
Select Case pstrNum
Case "1"
Return 9
Case "2"
Return 9
Case Else
Return 0
End Select
End Get
End Property
End Class
任何想法将不胜感激。