Using a generic list's findall() method

  • Thread starter Thread starter hardieca
  • Start date Start date
H

hardieca

Hi,

I have a list of sections that contain a parent section ID field that
indicates hierarchy throughout a website. I want to filter out all non-
root level sections, as indicated by a section ID of -1, so I tried
using the findall method.

Dim rootSectionList As New SectionList()

rootSectionList = mySectionList.FindAll(AddressOf isRootSection)

Which in turn calls:

Private Shared Function isRootSection(ByVal sec As Section) As Boolean
If sec.SectionID < 0 Then
Return True
Else
Return False
End If
End Function

I am getting the error: Unable to cast object of type
System.Collections.Generic.List`1[Deais.Pps.BO.Section]' to type
'Deais.Pps.BO.SectionList'.

Does anyone have any ideas what I'm doing wrong?

Thanks,

Chris
 
Hi,

I have a list of sections that contain a parent section ID field that
indicates hierarchy throughout a website. I want to filter out all non-
root level sections, as indicated by a section ID of -1, so I tried
using the findall method.

Dim rootSectionList As New SectionList()

rootSectionList = mySectionList.FindAll(AddressOf isRootSection)

Which in turn calls:

Private Shared Function isRootSection(ByVal sec As Section) As Boolean
If sec.SectionID < 0 Then
Return True
Else
Return False
End If
End Function

I am getting the error: Unable to cast object of type
System.Collections.Generic.List`1[Deais.Pps.BO.Section]' to type
'Deais.Pps.BO.SectionList'.

Does anyone have any ideas what I'm doing wrong?

Thanks,

Chris

The FindAll method returns a List(Of Section), not a SectionList. You
need a reference of type List(Of Section) to store it in.

Also, you only need the reference. The object that you created will only
be thrown away when you assign the new list to the reference.
 
Back
Top