Using LINQ, select list of objects inside another list of objects

前端 未结 2 1739
北恋
北恋 2020-12-24 01:00
public class ClassA
{
     public string MyString {get; set;}
}

public class ClassB
{
     public List MyObjects {get; set;}
}

List cla         


        
2条回答
  •  隐瞒了意图╮
    2020-12-24 01:43

    You want to use IEnumerable.SelectMany() Extension Method to flatten the hierarchy:

    var result = classBList.SelectMany(b => b.MyObjects).Distinct();
    

提交回复
热议问题