我正在尝试创建一个属性数组。为了简化我的问题,我创建了一个迷你项目
项目:我有3个形状,当我按下按钮时会改变颜色和数字。 我为每组属性创建了一个类。
Public Class Shape
Dim _color As Color
End Class
添加几个对象进行测试(首先编码颜色)
Public Shared Sub Main()
Dim ShapeList As New List(Of Shape)
ShapeList .Add(New Shape() With {_color = Color.Blue})
ShapeList .Add(New Shape() With {_color = Color.Green})
ShapeList .Add(New Shape() With {_color = Color.Red})
Display()
End Sub
按下按钮时,我希望显示一个对象数组中的排序/随机集
Public Sub Display(ByVal ShapeList As Object)
Dim ScreenObject As Array
ScreenObject(0) With {.OvalShape1} 'This is where I am stuck
ScreenObject(1) = .OvalShape2 'How to create this property in the
'ScreenObject array?
For Each obj As Shape In ShapeList
ScreenObject(0).Color = ShapeList(0).Color
End Sub
澄清:这三种形状分别是OvalShape1,2和3。但是对于我在VB中的小技巧,我很难找到答案。