Reputation: 39059
Still trying to wrap my head around LINQ coming from the Java and Objective-C world. Is there a way to accomplish the following loop with LINQ?
foreach(MyData d in mydata)
{
TreeNode n = new TreeNode(d.DisplayName);
this.myTree.Nodes.Add(n);
}
Upvotes: 0
Views: 466
Reputation: 24322
Try,
myTree.Nodes.AddRange(myData.Select(n => new TreeNode(n.DisplayName)).ToArray());
Upvotes: 2
Reputation: 13248
myTree.Nodes.AddRange(myData.Select(n => new TreeNode(n.DisplayName)).ToArray());
Upvotes: 2