2010-07-28 6 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 

End ClassComment supprimer des éléments de la liste multidimensionnelle 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 

Répondre

1

Comment LINQ aider ici, en particulier dans VB.NET?

Quoi qu'il en soit, vous ne semblez pas avoir une liste multidimensionnelle du tout, mais plutôt une collection de classes.

Cela devrait fonctionner si vous voulez une nouvelle liste sans ces articles:

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

Dans la syntaxe comme requête est:

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

grpSelectionList = g.ToList() 

Qu'est-ce que vous avez actuellement ne devrait pas travailler de toute façon que vous modifiez la collection sur laquelle vous itérez. Quoi qu'il en soit, vous pouvez le faire:

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