1
我想使用變量調用集合內的屬性。我有多個屬性,我不想只爲了獲取信息而使用case語句。這裏是代碼示例vb.net中的變量調用集合屬性
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
任何想法將不勝感激。