我有一個包含許多屬性的對象列表。檢查列表<Of List<T>>是否包含列表<T>
Dim Duplicates As New List(Of ElementObject)
Dim ListOfDuplicates As New List(Of List(Of ElementObject))
For Each Element As ElementObject In Duplicates
Dim tmpList As List(Of ElementObject)
'Im looking for list of elements with the same width and height in Duplicates list
tmpList = Duplicates.FindAll(Function(x) x.Width = Element.Width And x.Height = Element.Height)
tmpList = tmpLista.OrderBy(Function(x) x.Id).ToList()
'Here is what I want: I want to look if tmpLista is already in ListOfDuplicates, but this code does not work
If ListOfDuplicates.Contains(tmpList) Then
Continue For
End If
ListOfDuplicates.Add(tmpList)
Next
我該如何做到這一點,檢查我的另一個列表中的對象列表是否已經包含該列表?
'tmpLista'在'tmpList = tmpLista.OrderBy(功能(X)x.Id).ToList()'似乎是一個錯字。 –
不,不是,我只是改變了我的變量的命名,並忘記更改tmpList :) – XardasLord
您的代碼無法工作,因爲每當您執行檢查時,tmpList都是新創建的列表。 –