Visual Basic.Net ain't half bad

There I said it.

I'm a C# guy. Now about 4 years when I started with .Net I started writing in VB.Net but I quickly decided to move C#. This, despite having spent the 3+ years prior working in ASP Classic. After a little bit of C# I quickly adopted the typical C# snobbish opinion of VB. For no good reason mind you, just cause it was different.

My how things change.

I've joined a VB team and instead of trying to make the team change to C# I figured I'd just get back to VB. Also we do a lot of work with XML so it got me looking into the VB 9.0 XML features and I found that you can do things like this:

   1:  Imports <xmlns:ns="http://contacts">
   2:   
   3:  Dim contact1 As XElement = _
   4:      <contact>
   5:        <name>Joe Bloggs</name>
   6:        <phone type="home">09-555-0144</phone>
   7:        <phone type="mobile">021-555-0145</phone>
   8:      </contact>

Okay, nifty and all, but what do you do from there...How about this?

   1:  Dim phoneTypes As XElement = _
   2:    <phoneTypes>
   3:        <%= From phone In contacts...<phone> _
   4:            Select <type><%= phone.@type %></type> _
   5:        %>
   6:    </phoneTypes>

And that will give you the following XML

<phoneTypes>
    <type>home</type>
    <type>mobile</type>
</phoneTypes>

That's rather cool and really useful with some of the stuff I'll be working on.

Check out the Overview of LINQ to XML in Visual Basic for more details

Now, I still want to say I'm a C# guy, but I think the snickering at the mention of VB stops now. 

No Comments