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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T10:45:11+00:00 2026-05-23T10:45:11+00:00

I have a nested ObservableCollection<Student> , from which how can I get a particular

  • 0

I have a nested ObservableCollection<Student>, from which how can I get a particular student based on Id value using LINQ or Lambda ? Here is my Student class:

public class Student
    {

        public Student()
        {

        }

        public string Name;
        public int ID;
        public ObservableCollection<Student> StudLists;
    }

So each student object can have again student collections and it can go like any number of nested levels. how we can do it LINQ or using Lambda ? I have tried with

var studs = StudCollections.Where(c => c.StudLists.Any(m => m.ID == 122));

But this is not giving exact Student item ? Any idea ?

  • 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-23T10:45:12+00:00Added an answer on May 23, 2026 at 10:45 am

    If you mean you want to search all descendants of StudCollections, then you could write an extension method like so:

    static public class LinqExtensions
    {
      static public IEnumerable<T> Descendants<T>(this IEnumerable<T> source, Func<T, IEnumerable<T>> DescendBy)
      {
        foreach (T value in source)
        {
            yield return value;
    
            foreach (T child in DescendBy(value).Descendants<T>(DescendBy))
            {
                yield return child;
            }
        }
      }
    }
    

    and use it like so:

    var students = StudCollections.Descendants(s => s.StudLists).Where(s => s.ID == 122);
    

    If you want one student with a matching id, use:

    var student = StudCollections.Descendants(s => s.StudLists).FirstOrDefault(s => s.ID == 122);
    
    if (student != null)
    {
      // access student info here
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a number of tables, which have nested tables. I using jQuery to
I have nested groupboxes, which logically represent nested data structures in my application. Let's
great community :) I have category list which have nested child category list, which
I have seen many posts about using ActivityGroups for when you have nested activities
I have nested iterator in my custom stack template class. The problem I get
I have nested li, which is for horizontal subnav menu. I am trying to
I have a tricky CSS situation here. Basically I have nested span tags that
please I need your help with a Linq expression: I have nested objects with
I have a treeview which binds to lots of nested ObservableCollections. Each level of
I have nested tabs in jquery tabs which are pretty simple to do if

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.