Reputation: 8146
I have a List nodes where Node is
public class Node
{
public Node Left
public Node Right
}
I'd like to extract a list which looks like this:
{nodes[0].Left, nodes[0].Right, nodes[1].Left, nodes[1].Right, ...}
I am trying with Aggregate, Concat, Select and SelectMany
Upvotes: 1
Views: 34
Reputation: 14007
Try this:
var qry =
from node in nodes
let nodeValues = new Node[] { node.Left, node.Right }
from subnode in nodeValues
select subnode;
This will eventually restult in a SelecMany
, just in query syntax.
Upvotes: 0
Reputation: 63065
with SelectMany
var result = list.SelectMany(x=>new List<Node>(){x.Left, x.Right}).ToList();
Upvotes: 3