• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 311
  • Last Modified:

LINQ cast to collection classes

I'm looking for a on-liner fix to the following problem.

I have the following collection class

Public Class Authors
	Inherits Collection(Of Author)
End Class

Open in new window

And a method to get some Authors

Dim myAuthorsCollection = AuthorModel.GetSomeAuthorDudes()

Open in new window

I run some LINQ

Dim filteredAuthors = myAuthorsCollection.Where(function(p) p.authorTypeID=1)

Open in new window

Now my problem, in the above example "filteredAuthors" is now an IEnumerable(Of Author), but I want to quickly get it back to an "Authors" collection.  Is there a simple way to do this, other than creating a new "Authors" collection and creating a for loop to add authors back to it?

1 Solution
I think you may have to take the looping approach but you can write an extension method so that you just call that method and get the collection out.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now