Hi,
I have been reading extensively about searching generic lists in VB.NET with the usage of delegates. However, I still cannot seem to grasp how to achieve what I want to, which I believe is frustratingly simple!
I have a list populated with instances of an object with three parameters (fields/variables). When I receive a new object to add to the list I want to search the list for the "layer" field. If the field matches then I will replace that row (object) in the list with the new object, if no match is found then I will add it to the list.
My object:
My List Variable:
This list is going to be a property of the object. The property:
So I have not come up with the predicate function yet. I am stumped!
I have been reading extensively about searching generic lists in VB.NET with the usage of delegates. However, I still cannot seem to grasp how to achieve what I want to, which I believe is frustratingly simple!
I have a list populated with instances of an object with three parameters (fields/variables). When I receive a new object to add to the list I want to search the list for the "layer" field. If the field matches then I will replace that row (object) in the list with the new object, if no match is found then I will add it to the list.
My object:
VB.NET:
Public Class LayertoAdd
Public Layer As String
Public QuanField As String
Public ClsField As String
Public Sub New(ByVal layer As String, ByVal QuanField As string, ByValClsField As String)
me.Layer = layer
Me.QuanField = QuanField
Me.ClsField = ClsField
End Sub
End Class
My List Variable:
VB.NET:
Private m_LayersFields As List(Of LayerToAdd) = New List(Of LayerToAdd)
This list is going to be a property of the object. The property:
VB.NET:
Public Property LHabParamList()
Get
Return m_LayersFields
End Get
Set (ByVal value)
Dim pLayerToAdd As LayerToAdd
pLayerToadd = value
' Here is where I am confused. I just want a boolean return
' true if the list contains a match in the .layer field of the LayerToAdd object
If m_LayersFields.Contains(...) = True Then
Else m_LayersFields.Add(pLayerToAdd)
End If
End Set
End Property
So I have not come up with the predicate function yet. I am stumped!