在下面的伪代码中,如果我有两个类,并且我希望在另一个类中初始化一个类而不必将名称设置为不同,那么我将如何实现这一目标?
'==Car.vb==
Public Class Car
Public Model as New Car.Model()
End Class
'==Model.vb==
Partial Class Car
Public Class Model
Public Enum Types
BMW
Audi
Yugo
End Enum
'Do Something
End Class
End Class
'==ASPX page==
Dim c as New Car()
c.Model = Car.Model.Types.BMW
显然这不起作用,因为New Model对象的名称与Car.Model类相同。我也不想每次定义一个汽车类时都要创建一个“模型”对象,但我也不希望这些名字都像这样愚蠢:
'==Car.vb==
Public Class Car
Public Model as New Car.CarModel()
End Class
'==Model.vb==
Partial Class Car
Public Class CarModel
Public Enum Types
BMW
Audi
Yugo
End Enum
'Do Something
End Class
End Class
'==ASPX page==
Dim c as New Car()
c.Model = Car.CarModel.Types.BMW
有没有更好的方法来做到这一点,所以我得到了我想要的使用代码的结果?
'==ASPX page==
Dim c as New Car()
c.Model = Car.Model.Types.BMW