S
Sam
Hi All
I have couple of question regarding property of a class and structures.
**** ---- Here is my class and structure ---- *****
1. Public Structure MyPoint
2. Dim p As Point
3. Dim ptColor As Color
4. End Structure
5. Public Class MyTriangle
6. Private _l(2) As MyPoint
7. Public Sub New(ByVal points() As MyPoint)
8. _l = points
9. End Sub
10. Default Public Property Item(ByVal index As Integer) As MyPoint
11. Get
12. Return (_l(index))
13. End Get
14. Set(ByVal value As MyPoint)
15. _l(index) = value
16. End Set
17. End Property
18. Public Property Points() As MyPoint()
19. Get
20. Return (_l)
21. End Get
22. Set(ByVal value As MyPoint())
23. _l = value
24. End Set
25. End Property
26. End Class
My questions are:
a. Is it normal to have a property that return an array as in my class line
18?
b. When I tried to assign a value such as Triangle(0).p.X = 5, the compiler
complained
Would anyone give me a hand?
Regards,
Sam
**** ---------------------------- *****
Here is what I tried
Dim v0, v1, v2 As MyPoint
Dim vertex(2) As MyPoint
vertex(0) = v0
vertex(1) = v1
vertex(2) = v2
Dim Triangle As New MyTriangle(vertex)
' The following statement give me an error
' "Epression is a value and therefore cannot be
' the target of an assignment
Triangle(0).p.X = 5
' However if I try this statement which access my
' property that returns an array, I'm ok
Triangle.Points(0).p.X = 5
I have couple of question regarding property of a class and structures.
**** ---- Here is my class and structure ---- *****
1. Public Structure MyPoint
2. Dim p As Point
3. Dim ptColor As Color
4. End Structure
5. Public Class MyTriangle
6. Private _l(2) As MyPoint
7. Public Sub New(ByVal points() As MyPoint)
8. _l = points
9. End Sub
10. Default Public Property Item(ByVal index As Integer) As MyPoint
11. Get
12. Return (_l(index))
13. End Get
14. Set(ByVal value As MyPoint)
15. _l(index) = value
16. End Set
17. End Property
18. Public Property Points() As MyPoint()
19. Get
20. Return (_l)
21. End Get
22. Set(ByVal value As MyPoint())
23. _l = value
24. End Set
25. End Property
26. End Class
My questions are:
a. Is it normal to have a property that return an array as in my class line
18?
b. When I tried to assign a value such as Triangle(0).p.X = 5, the compiler
complained
Would anyone give me a hand?
Regards,
Sam
**** ---------------------------- *****
Here is what I tried
Dim v0, v1, v2 As MyPoint
Dim vertex(2) As MyPoint
vertex(0) = v0
vertex(1) = v1
vertex(2) = v2
Dim Triangle As New MyTriangle(vertex)
' The following statement give me an error
' "Epression is a value and therefore cannot be
' the target of an assignment
Triangle(0).p.X = 5
' However if I try this statement which access my
' property that returns an array, I'm ok
Triangle.Points(0).p.X = 5