I am having trouble defining the get/set for an array in a class I have created.... how do you get/set arrays within classes? basically I have an array with x and y as width/height for a map i am creating, and i want each x/y point to have the "walkable" and "image" properties, a boolean and path respectively. here is the code...

Imports System.Drawing
Imports System.Drawing.Drawing2D
Imports System.IO

Public Class Tile
    Dim wlkable As Boolean
    Dim imge As Path

    Public Property walkable()
        Get
            Return wlkable
        End Get
        Set(ByVal value)
            wlkable = value
        End Set
    End Property

    Public Property image()
        Get
            Return imge
        End Get
        Set(ByVal value)
            imge = value
        End Set
    End Property

End Class

Public Class Map
    Inherits Tile
    Dim named As String
    Dim wdth As Integer
    Dim hght As Integer
    Dim dpth As Integer
    Dim Tils(wdth, hght) As Tile


    Public Property name()
        Get
            Return named
        End Get
        Set(ByVal value)
            named = value
        End Set
    End Property

    Public Property width()
        Get
            Return wdth
        End Get
        Set(ByVal value)
            wdth = value
        End Set
    End Property

    Public Property height()
        Get
            Return hght
        End Get
        Set(ByVal value)
            hght = value
        End Set
    End Property

    Public Property depth()
        Get
            Return dpth
        End Get
        Set(ByVal value)
            dpth = value
        End Set
    End Property

    Public Property tiles()
        Get
            For x = 0 To Me.wdth
                For y = 0 To Me.hght
'''''''''''''This is where I am getting the trouble, not sure how to handle this...:
                    Return Tils(x, y).walkable
                    Return Tils(x, y).image
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
                Next
            Next
        End Get

        Set(ByVal value)
            Tils = value
        End Set
    End Property

End Class

Hi, To use array in property u can specify the Property type as array

Dim mWalkable as Boolean()
   ' OR Dim mWalkable() as Boolean
   Public Property Walkable() As Boolean()
        Get
            Return mWalkable
        End Get
        Set(ByVal value As Boolean())
            mWalkable = value
        End Set
    End Property

Example for array in Class

Public Class Title
    Dim mWalkable() As Boolean

    Public Property Walkable() As Boolean()
        Get
            Return mWalkable
        End Get
        Set(ByVal value As Boolean())
            mWalkable = value
        End Set
    End Property
    Public Overrides Function ToString() As String
        Dim str As String = ""
        For Each bool As Boolean In mWalkable
            str &= bool.ToString() & " "
        Next
        Return str
    End Function
End Class

and To Check this Class

Dim tit As Title
        tit = New Title()
        tit.Walkable = New Boolean() {True, False, True, False}
        MessageBox.Show(tit.ToString())
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.