【问题标题】:How to loop within a Linq to XML statement如何在 Linq to XML 语句中循环
【发布时间】:2011-05-08 11:08:13
【问题描述】:

我该怎么做:

XDocument xDocument = new XDocument(new XElement("SqlInstall",
            new XElement("Catalogs",
                    new XElement("Install"),
                    foreach (var item in packagedProduct.Installs)
                    {
                            new XElement("File ")..
                    }

                    ))));

它用“invalid expression term foreach”抱怨 Linq 语句中的 foreach 循环

【问题讨论】:

    标签: c# .net xml linq


    【解决方案1】:

    foreach 循环应该这样重写:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-08-15
      相关资源
      最近更新 更多