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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T09:11:25+00:00 2026-06-05T09:11:25+00:00

I have a list of Persons which has children [same type]. I get the

  • 0

I have a list of Persons which has children [same type]. I get the list from xml file.

Scenario :

Person : Id, Name, Gender, Age, Children [Class with fields]

If personList has 1,2,5 Ids,
2 and 5 with children 3,4 and 6,7,8 respectively.
I have to get the max id as 8.

How do i get the max of Id from PersonList using lambda expression?

  • 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-06-05T09:11:29+00:00Added an answer on June 5, 2026 at 9:11 am

    You could try a combination of Concat and SelectMany (that’s assuming it’s only nested one level):

    var maxId = personList.Concat(personList.SelectMany(p => p.Children)).Max(p => p.Id);
    

    UPDATE
    If you have multiple nesting levels, you could also write an extension method to make SelectMany recursive:

    public static IEnumerable<T> SelectManyRecursive<T>(this IEnumerable<T> source, Func<T, IEnumerable<T>> selector) {
        if (source == null) { yield break; }
        foreach (var item in source) {
            yield return item;
            foreach (var selected in selector(item).SelectManyRecursive(selector)) {
                yield return selected;
            }
        }
    }
    

    That doesn’t handle circular references and it behaves differently than SelectMany by also returning the items in the source collection itself (so you might want to change the name), but otherwise i think it does the job. You could use it quite easily:

    var maxId = personList.SelectManyRecursive(p => p.Children).Max(p => p.Id);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a person class which has a name and a list of friends
Okay here is the scenario! I have a Person object which has an Address
Having: an entity Person which has a propriety Name a List<string> names loaded with
I have a list of person objects which I want to send in response
I have a list of Persons inside a Company Class. public class Company{ IList<Person>
I have a sharepoint list which has several fields. It seems that when a
Lets say I have a flat list of objects, each of which has a
I have a list of Person s each which have multiple fields that I
I have an object which has a date and a list of people, a
In my Core Data app, I have an entity Person (which has a fullname

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.