How to loop in a Linq to XML expression

How can i do this:

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

                    ))));

He complains about a foreach loop in a Linq expression with an "invalid foreach expression"

+3
source share
1 answer

The foreach loop should be rewritten as follows:

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

Source: https://habr.com/ru/post/1774301/


All Articles