2010-07-28 50 views
0
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 

末级如何使用LINQ

//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

LINQ如何将帮助这里,特别是在VB.NET中删除从多维的列表项?

无论如何,你似乎没有多维列表,而是一个类集合。

,如果你想没有这些项目的新名单这应该工作:

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

在被查询的语法:

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

grpSelectionList = g.ToList() 

什么,你现在有没有无论如何都应该作为工作你正在修改你正在迭代的集合。无论如何,你可以这样做:

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))