/* using System; using System.Linq; using System.Xml.Linq; */
var numbers =
from n in Enumerable.Range( 1, 20 )
let attributes =
new Object[]{
new XAttribute( "value", n ),
new XAttribute( "squared", n * n ) }
select new XElement( "number", attributes );
XElement document = new XElement( "numbers", numbers );
Console.WriteLine( document.ToString() );
/*
This code is derived from Mike Taulty (Microsoft UK Ltd.) here:
http://mtaulty.com/downloads/MTLaunchLINQXML.zip
For more information, see
“LINQ Talk at UK Visual Studio 2008 Launch”
http://mtaulty.com/CommunityServer/blogs/mike_taultys_blog/
archive/2008/03/20/10255.aspx
*/