Reputation: 17653
My code is supposed to remove item from list but its not removing item.
My Code:
dim myRoom as Room = New Room()
Dim myRoomList as List( of Room ) = new List( of Room )
...
myRoomList.add(myRoom)
msgbox(myRoomList.count)
...
myRoomList.remove(myRoom)
msgbox(myRoomList.count)
Upvotes: 0
Views: 6377
Reputation: 545528
The only possible reason for this not to remove the item is when you have overriden the Equals
method of the Room
class with errors. For example, the following code would exhibit such a behaviour:
Class Room
Public Overrides Function Equals(ByVal obj As Object) As Boolean
Return False
End Function
End Class
If that’s not the case, then the error is elsewhere and the code you have shown us does in fact work.
Upvotes: 1
Reputation: 2901
Are you sure that there is no item being added before the removal, so that the count is not increased again. Try using this for a test...
dim myRoom as Room = New Room()
Dim myRoomList as List( of Room ) = new List( of Room )
...
myRoomList.add(myRoom)
msgbox(myRoomList.count)
...
msgbox(myRoomList.count)
myRoomList.remove(myRoom)
msgbox(myRoomList.count)
Upvotes: 1