code_junkie

Is there a way to convert an IEnumerable into a collection of XElements

Nov 13th, 2011
178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.40 KB | None | 0 0
  1. List<string> collection = new List<string>() {"1", "2", "3"}
  2.  
  3. <Collection>
  4. <Element>1</Element>
  5. <Element>2</Element>
  6. <Element>3</Element>
  7. </Collection>
  8.  
  9. XElement Configuration =
  10. new XElement("Configuration",
  11. new XElement("Collection", collection.ToArray()
  12. ),
  13. );
  14.  
  15. XElement Configuration = new XElement("Collection",
  16. collection.Select(c=>new XElement("Element", c)));
Add Comment
Please, Sign In to add comment