tags:

views:

139

answers:

4

I don't want a war between VB.NET and C# developers, neither is my goal to open a C# VS VB.NET confrontation.

I would like you all to list a feature that is heavily used in C#, but is not available in VB.NET 2.0, and how would you work around to achieve a similar behaviour or purpose?

For example:

C#

Accepts void (return) lambda expressions. Here's an example with FNH mapping:

Component(x => x.Address, m => { 
    m.Map(x => x.Number); 
    m.Map(x => x.Street); 
    m.Map(x => x.PostCode); 
});

This is impossible to do before VB.NET 4.0 (supposed to be doable in VB.NET 4.0)

VB.NET

Must write a helping method (Sub), and provide the AddressOf this method in order to workaround.

Private Sub Helper(ByVal m As MType) 
    m.Map(Function(x) x.Number) 
    m.Map(Function(x) x.Street) 
    m.Map(Function(x) x.PostCode) 
End Sub 

...   
Component(Function(x) x.Address, AddressOf Helper) 

Now I know, it is not VB.NET 2.0, but this is an example. VB.NET 3.0 and 3.5 can used too. Please just mention what version of VB.NET this refers to.

+7  A: 

Iterator blocks (yield return/yield break) is probably the biggest.

Joel Coehoorn
Thanks! Would there be a workaround?
Will Marcouiller
The workaround is to code the IEnumerable or IEnumerator classes manually.
Brian Gideon
Thanks Brian! =)
Will Marcouiller
+3  A: 

You could check out the wiki for a comparison. See sections "Features of Visual Basic .NET not found in C#" and "Features of C# not found in Visual Basic .NET".

SwDevMan81
Thanks! I didn't know about it. Do they present workarounds?
Will Marcouiller
@SwDevMan81: The link is pretty interesting! =)
Will Marcouiller
Yeah, they don't list workarounds for any of them. Some of them wont have workarounds like multi-line comments (with the exception of just using a bunch of single line comments back to back).
SwDevMan81
+1  A: 

For me something that I miss is implicit interface definitions:

ISomething
{
   void Execute();
}

class ASomething : ISomething
{
   public void Execute()
  {
    //Do something
  }
}

Is fine. In VB.net you have to explicitly mark the method as implementing the interface, which I find to be quite a nuisance. I know that there are people that prefer this technique, but not for me...

Paddy
That is something I miss a lot too! It took me time to get used to it. Every now and then, to simply press [Enter] when the Implements IInterface is reported as an error, then it will automatically implement the interface, writing every "Implements IInterface.Member" required. By chance that exists! Otherwise it would be a pain! But you're right. =)
Will Marcouiller
+1  A: 

Unsafe code block via the unsafe keyword are not allowed in VB.NET. There is no workaround. But, honestly, I have never used the feature anyway. If I encounter a situation that would typically require this feature I usually punt and move straight to C++/CLI.

Brian Gideon