如何在Linq to XML语句中循环?

3
我该如何实现这个功能:
XDocument xDocument = new XDocument(new XElement("SqlInstall",
            new XElement("Catalogs",
                    new XElement("Install"),
                    foreach (var item in packagedProduct.Installs)
                    {
                            new XElement("File ")..
                    }

                    ))));

它抱怨Linq语句中的foreach循环出现“无效表达式项foreach”。
1个回答

7

foreach循环应该重写成如下形式:

packagedProduct.Installs.Select( item => new XElement("File ").. );

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接