Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1110755
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T02:26:33+00:00 2026-05-17T02:26:33+00:00

This is probably me just remembering things completely backwards, but I’d like to know

  • 0

This is probably me just remembering things completely backwards, but I’d like to know more about what I’m doing wrong…

I have declared a class to be nothing more than a direct inheritance from a generic list (done to simplify naming), something like this:

public class FooList : List<Foo> {}

now in another method completely separate from this class, I am trying to return an instance of this class, however I want to filter the class based on a criterion, so I’m using a lambda expression:

var list = new FooList(); // imagine this fills it with different items
var filtered = list.FindAll(c => c.Something == "filter criteria");

now according to the FindAll method, this SHOULD return a List[Foo]. However, I want to return this object as a FooList, not a List[Foo]. Do I have to create a new instance of FooList and copy the items from the List[Foo]?

If so, why? why can’t I convert a List to a FooList directly, since they are the same object?

If this CAN be done, how do I do it?

many thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T02:26:34+00:00Added an answer on May 17, 2026 at 2:26 am

    They are not the same thing. A FooList is a List<foo> but a List<foo>, which is being returned by the FindAll() function inherited from List<foo>, is not a FooList. You will need to construct a new FooList.

    You could do something like create a Constructor for FooList that takes a IEnumerable<foo> object like this:

    class FooList : List<foo>
    {
       public FooList(IEnumerable<foo> l)
            : base(l)
       {  }
    }
    

    Or you could also do something like this:

     var list = new FooList();
     var filtered = list.FindAll(c => c.Something == "filter criteria");
     var newList = new FooList();
     newList.AddRange(filtered);
     return newList;
    

    However as mentioned in some of the other answers, if you are not adding any functionality then you should just create an alias with the using keyword.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is probably quite simple, but I just don't know how to do this...
I know this question is probably stoopid. But I just don't want to cause
I know this probably seems like a little problem. It just feels like there
Ok this is probably just me not knowing enough about php but here it
I know this is probably just a terminology mismatch but if i'm not mistaken
I know that this probably doesn't really matter, but I would like to know
Hey guys I know that this is probably just a simple sql statement but
This is probably a pretty basic question, but just something that I wanted to
This is probably a no brainer but... I've just opened a solution in VS2008
This is probably just a crazy pipe dream but I thought I would ask

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.