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?
You could try a combination of
ConcatandSelectMany(that’s assuming it’s only nested one level):UPDATE
If you have multiple nesting levels, you could also write an extension method to make
SelectManyrecursive:That doesn’t handle circular references and it behaves differently than
SelectManyby 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: