Arrays 布尔值在再次访问时设置为False?

Arrays 布尔值在再次访问时设置为False?,arrays,vb.net,list,boolean,Arrays,Vb.net,List,Boolean,每当我尝试对一个变量进行操作时,它会立即设置为false。此方法应将存储在box\u列表中的box对象上的full属性设置为True。它会找到正确的框并更改属性,但每当再次访问它时,它就会变为false Public Sub DefineFilled() Dim ship As New Ship(Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing) Dim x As Integer = 0 Dim y

每当我尝试对一个变量进行操作时,它会立即设置为false。此方法应将存储在
box\u列表中的
box
对象上的
full
属性设置为True。它会找到正确的框并更改属性,但每当再次访问它时,它就会变为false

Public Sub DefineFilled()
    Dim ship As New Ship(Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing)
    Dim x As Integer = 0
    Dim y As Integer = 0

    ship = AirCraftCarrier
    If ship.has_moved Then
        Debug.Print("")
        For i As Integer = 0 To ship.length - 1
            x = ship.space_filled(i, 0) 'space_filled is a list that stores each point that the ship takes up on the grid
            y = ship.space_filled(i, 1) 
            PlayerBoard.box_list(x, y).full = True 'Sets variable to True

            Debug.Print(PlayerBoard.box_list(x, y).full) 'Prints variable as False
        Next
    End If
End Sub
编辑1:排行榜定义

(主要部分)

(董事会级别)

编辑2:框列表的定义方式(在board类中)

编辑3:框的定义

Public Class Box
    Dim _image As PictureBox
    Public Property image() As PictureBox
        Get
            Return _image
        End Get
        Set(ByVal value As PictureBox)
            _image = value
        End Set
    End Property
    Dim _full As Boolean
    Public Property full() As Boolean
        Get
            Return _full
        End Get
        Set(ByVal value As Boolean)
            _full = full
        End Set
    End Property

    Public Sub New(ByVal location_x As Integer, ByVal location_y As Integer, ByVal imagep As PictureBox)
        image = imagep
    End Sub

End Class

此代码的问题在于
类上的
full
属性

你现在写的是这样的:

Public Property full() As Boolean
    Get
        Return _full
    End Get
    Set(ByVal value As Boolean)
        _full = full
    End Set
End Property
应该是这样的:

Public Property full() As Boolean
    Get
        Return _full
    End Get
    Set(ByVal value As Boolean)
        _full = value
    End Set
End Property

您当前的代码正在递归地将属性设置回它自己的值。因此,它将保持
false

我们需要查看任何类型的Playboard的定义,尤其是box\u list函数。已添加。希望我得到了所有相关的东西。附带问题:去掉box_list()属性的Set选项。你不会想要的。删除集合后,您仍可以更改该数组中的元素。另外:
状态\u norepro
。我用这段代码构建的示例程序工作正常。还有一些东西你没给我们看。。。可能重新声明您的对象实例。@alexanderd5398您仍然可以在不使用集合的情况下更改数组中的元素。唯一不能做的就是在一次赋值中替换整个数组。例如,如果没有setter:
playboard.box\u list(x,y).full=True
,这仍然有效。这也是:
playboard.box\u list(x,y)=newbox()
。这两个选项都只使用Get选项。但这不起作用:
playboard.box\u list=newbox(9,9)
。了解这一点将大大有助于您了解对象的实际工作原理。非常感谢!我真不敢相信我错过了:没问题。有时是一些小事让我们绊倒。
Public Class Box
    Dim _image As PictureBox
    Public Property image() As PictureBox
        Get
            Return _image
        End Get
        Set(ByVal value As PictureBox)
            _image = value
        End Set
    End Property
    Dim _full As Boolean
    Public Property full() As Boolean
        Get
            Return _full
        End Get
        Set(ByVal value As Boolean)
            _full = full
        End Set
    End Property

    Public Sub New(ByVal location_x As Integer, ByVal location_y As Integer, ByVal imagep As PictureBox)
        image = imagep
    End Sub

End Class
Public Property full() As Boolean
    Get
        Return _full
    End Get
    Set(ByVal value As Boolean)
        _full = full
    End Set
End Property
Public Property full() As Boolean
    Get
        Return _full
    End Get
    Set(ByVal value As Boolean)
        _full = value
    End Set
End Property