Mike Taulty's Blog
Bits and Bytes from Microsoft UK
Can C# V3.0 Please Have the VB9 XML Syntax?

Blogs

Mike Taulty's Blog

Elsewhere

Archives

Here's my online petition.

I really like the new VB9 syntax for dealing with XElement and friends in order to construct an XML document.

Can we please have that in C# V3.0 as well? :-)

Anyone agree?

Here's some C# that creates some XML (meant to be RSS but I've not checked that it actually is);

 

feed = 
      new XElement("rss",
        new XAttribute("version", "2.0"),
        new XElement("channel",
          new XElement("title", "Mike's Blog"),
          new XElement("link", "http://mtaulty.com"),
          new XElement("description", "Mike's Great Rss Feed"),

            from postNumber in new int[] { 1, 2, 3 }
            select 
              new XElement("item",
               new XElement("title", "Post Number " + postNumber.ToString()),
               new XElement("link", "http://mtaulty.com" + postNumber.ToString()),
               new XElement("description", "Description " + postNumber.ToString()))));   
    

Here's the corresponding VB;

 

    Dim feed As XElement = _
      <rss version="2.0">
        <channel>
          <title>Mike's Blog</title>
          <link>http://mtaulty.com</link>
          <description>Mike's Great Rss Feed</description>

          <%= _
          From n In New Integer() {1, 2, 3} _
            Select _
              <item>
                <title>
                  <%= "Post Number" + CStr(n) %>
                </title>
                <link>
                  <%= "http://mtaulty.com/Post" + CStr(n) %>
                </link>
                <description>
                  <%= "Description " + CStr(n) %>
                </description>
              </item> _
          %>

        </channel>
      </rss>

For me, this should be in both languages.


Posted Fri, Feb 16 2007 4:05 AM by mtaulty