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 6933937
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T11:53:47+00:00 2026-05-27T11:53:47+00:00

Let’s say I have instance of MyCollection class called Foo1. MyCollection is basically a

  • 0

Let’s say I have instance of MyCollection class called Foo1. MyCollection is basically a collection of MyClass. Not sure how can I do something like below with or without a cast?

MyCollection Foo2 =  Foo1.Where( r => r.LastName == “SomeName”)

NOTE: MyCollection & MyClass are something from a 3rd party library. I probably can create extension method on it but hoping to have some easy way of doing it.

  • 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-27T11:53:47+00:00Added an answer on May 27, 2026 at 11:53 am

    If you want to have a new instance of MyCollection holding only those elements that meet the criteria, you can create a Where method on your class.

    Or, you can rely on the linq extension method on IEnumerable<T> (assuming your class implements IEnumerable<MyClass>), and use whatever method you would normally use for populating a MyCollection from a sequence of MyClass objects.

    EDIT

    Example of linq extension method approach:

    • ensure that MyCollection implements IEnumerable<MyClass>
    • ensure that MyCollection has a constructor that accepts an IEnumerable<MyClass>
    • include #using System.Linq;
    • example statement: MyCollection Foo2 = new MyCollection(Foo1.Where( r => r.LastName == “SomeName”));

    EDIT EDIT

    I see now that MyClass and MyCollection are third-party types. I had assumed from the “my” bit that you were designing them yourself.

    The MyCollection type almost certainly implements IEnumerable<MyClass> — if it doesn’t, it may implement the non-generic IEnumerable. In that case, you can use the Cast<T> extension method. If it implements neither interface, the third-party library is somewhat lacking.

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

Sidebar

Related Questions

Let's say I have 2 instance of a class called 'Animal'. Animal has 3
Let's say I have a class A which can fire an event called X.
Let's say I have a MyObject instance which is not initialized: var a:MyObject =
Let's say we have a class foo which has a private instance variable bar
Let's say I have a class Foo with some primitive instance variables. I initialize
Let say I have abstract class called: Tenant and Customer. The tenant in this
Let's say we have a class: public class MyClass { @Autowired private AnotherBean anotherBean;
Let's say I have this class: public abstract class CustomerCollectionBase : Collection<Customer>{} One of
Let's say I have a java.lang.Class instance, c at runtime. At runtime, is there
let's say if you have class doing something on some other thread. And has

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.