如何更改对象列表中 1 个(或多个)指定项的 1 个属性
Class Item
Private _Id As Integer
Private _Value As Boolean 'can be string, int , .....
Public Property Id() As Integer
Get
Return _Id
End Get
Set(ByVal value As Integer)
_Id = value
End Set
End Property
Public Property Value() As Boolean
Get
Return _Value
End Get
Set(ByVal value As Boolean)
_Value = value
End Set
End Property
Public Sub New(ByVal id As Integer, ByVal value As Boolean)
Me.Id = id
Me.Value = value
End Sub
End Class
...
Dim lst As New List(Of Item)
lst.Add(New Item(1, True))
lst.Add(New Item(2, True))
lst.Add(New Item(3, True))
lst = from l in lst select l ' and change the value of the element 2 to FALSE
结果
之前的列表
Item
[_Id = 1]
[_Value = True]
Item
[_Id = 2]
[_Value = True]
Item
[_Id = 3]
[_Value = True]
之后列出
Item
[_Id = 1]
[_Value = True]
Item
[_Id = 2]
[_Value = False]
Item
[_Id = 3]
[_Value = True]