OK, this is one that gets me every time I switch back to Visual Basic from C#, and is one of the times that I find C# much easier to work with. Even with all the XML Literal goodness in Visual Basic 9, these types of things make me want to just code in C#.
When you try to implement 2 different interfaces that have the same member name, but return 2 different types, the syntax in C# is sooooo much easier to read and work with. In this case, it I'm writing my own Query Provider for a pet project I'm working on, and the generic Query class needs to implement both IEnumerable(Of T) and IEnumerable. Both Interfaces require a function called GetEnumerator, but the generic version of the Interface return a type of IEnumerator(Of T), and the non-generic version returns IEnumerator. Here's what it looks like in C#:
public IEnumerator<T> GetEnumerator()
{
return ((IEnumerable<T>)this.provider.Execute(this.BLOCKED EXPRESSION.GetEnumerator();
}
IEnumerator IEnumerable.GetEnumerator()
{
return ((IEnumerable)this.provider.Execute(this.BLOCKED EXPRESSION.GetEnumerator();
}
Now, the same thing, but in Visual Basic:
Public Function GetEnumerator() As IEnumerator(Of T) Implements IEnumerable(Of T).GetEnumerator
Return DirectCast(Me._Provider.Execute(Me._Expression), IEnumerable(Of T)).GetEnumerator
End Function
Private Function GetEnumerator1() As IEnumerator Implements IEnumerable.GetEnumerator
Return DirectCast(Me._Provider.Execute(Me._Expression), IEnumerable).GetEnumerator
End Function
Do you see the difference? In C# I can just declare the function name as IEnumerable.GetEnumerator, where in VB I have to use a different function name and then use the Implements keyword to specify the name of the interface and the name of the method is being implemented. Because our code reads left to right, I read the method name first. In C#, all the important information is all together, but in VB, I have to read beyond the method name to the Implements phrase to find out where this member maps to, and when you are typing this, it is even harder (Intellisense does help here).
Oh, and if you use either of the common C# to Visual Basic conversion methods, KamalPatel's site or (my favorite) Reflector both do not convert this correctly. Here's their converted code
Private Function IEnumerable.GetEnumerator() As IEnumerator
Return (CType(Me.Provider.Execute(Me.Expression), IEnumerable)).GetEnumerator()
End Function
Which of course will not compile.