By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,466 Members | 1,172 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,466 IT Pros & Developers. It's quick & easy.

Using a generic list's findall() method

P: n/a
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

Jul 13 '07 #1
Share this Question
Share on Google+
1 Reply


P: n/a
ha******@hotmail.com wrote:
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.

--
Göran Andersson
_____
http://www.guffa.com
Jul 13 '07 #2

This discussion thread is closed

Replies have been disabled for this discussion.