我有一個類似於下面的示例設置我想要定義變量(var1)基於一些信息,當它被實例化時傳遞到類中。我怎麼做?如何有條件地定義變量?
Public Class myClass
Private var1 as someClass
Public Sub New(which_type as string)
if which_type = "a" then
' I need var to be a certain type of class
var1 = new SomeClass()
elseif which_type = "b" then
' I need var1 to be a different type of class
var1 = new SomeOtherClass()
end if
End Sub
End Class
var1只能是一個或另一個......除非從另一個繼承 – Plutonix