我有一个对象:
public class MyObject
{
public int Id { get; set; }
public List<MyObject> Items { get; set; }
}
我有 MyObject 的列表:
List<MyObject> collection = new List<MyObject>();
collection.Add(new MyObject()
{
Id = 1,
Items = null
});
collection.Add(new MyObject()
{
Id = 2,
Items = null
});
collection.Add(new MyObject()
{
Id = 3,
Items = null
});
List<MyObject> collectionMyObject = new List<MyObject>();
collectionMyObject.Add(new MyObject()
{
Id = 4,
Items = collection
});
collectionMyObject.Add(new MyObject()
{
Id = 5,
Items = null
});
如何使用 Linq 在 collectionMyObject 中找到 Id = 2 的对象?