What features are heavily used in C# 2.0, but is not available in VBNET 2.0, and how to workaround?
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.
Iterator blocks (yield return/yield break) is probably the biggest.
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".
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...
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.
精彩评论