仍然试图围绕来自Java和Objective-C世界的LINQ。有没有办法用LINQ完成以下循环?
foreach(MyData d in mydata)
{
TreeNode n = new TreeNode(d.DisplayName);
this.myTree.Nodes.Add(n);
}
答案 0 :(得分:2)
myTree.Nodes.AddRange(myData.Select(n => new TreeNode(n.DisplayName)).ToArray());
答案 1 :(得分:2)
尝试,
myTree.Nodes.AddRange(myData.Select(n => new TreeNode(n.DisplayName)).ToArray());