tags:

views:

19

answers:

1
    Public Class GroupSelect
Public Property RowNo() As Integer
    Get
        Return m_RowNo
    End Get
    Set(ByVal value As Integer)
        m_RowNo = value
    End Set
End Property
Private m_RowNo As Integer
Public Property GroupNo() As Integer
    Get
        Return m_GroupNo
    End Get
    Set(ByVal value As Integer)
        m_GroupNo = value
    End Set
End Property
Private m_GroupNo As Integer

End Class

//Here I need to write LINQ statement and replace below code

For Each item As GroupSelect In grpSelectionList
                    If item.RowNo = rowNo And item.GroupNo = grpNo Then
                        grpSelectionList.Remove(item)
                 End If
                Next
+1  A: 

How would LINQ help here, particularly in VB.NET?

Anyway, you don't appear to have a multidimensional list at all but rather a class collection.

This should work if you want a new list without those items:

grpSelectionList = grpSelectionList _
.Where(Function(g) g.RowNo <> RowNo AndAlso g.GroupNo <> grpNo).ToList()

In the query-like syntax that is:

Dim g = From g in grpSelectionList _
Where g.RowNo <> RowNo AndAlso g.GroupNo <> grpNo _
Select g

grpSelectionList = g.ToList()

What you currently have shouldn't work anyway as you are modifying the collection you are iterating over. Anyway you could do this:

Dim tempList as List(Of GroupSelect) = grpSelectionList

tempList _
.Where(Function(g) g.RowNo = RowNo AndAlso g.GroupNo = grpNo) _
.ToList() _
.ForEach(Function(g) grpSelectionList.Remove(g))
Graphain