I have learned quite a bit browsing through Hidden Features of C# and was surprised when I couldn't find something similar for VB.NET.
So what are some of its hidden or lesser known features?
I have learned quite a bit browsing through Hidden Features of C# and was surprised when I couldn't find something similar for VB.NET.
So what are some of its hidden or lesser known features?
This is a nice one. The Select Case statement within VB.Net is very powerful.
Sure there is the standard
But there is more...
You can do ranges:
And even more...
You can (although may not be a good idea) do boolean checks on multiple variables:
Typedefs
VB knows a primitive kind of
typedef
viaImport
aliases:This is more useful when used in conjunction with generic types:
This is built-in, and a definite advantage over C#. The ability to implement an interface Method without having to use the same name.
Such as:
Import aliases are also largely unknown:
DateTime can be initialized by surrounding your date with #
You can also use type inference along with this syntax
That's a lot nicer than using the constructor
Custom
Enum
sOne of the real hidden features of VB is the
completionlist
XML documentation tag that can be used to create ownEnum
-like types with extended functionality. This feature doesn't work in C#, though.One example from a recent code of mine:
Now, when assigning a value to a variable declared as
Rule
, the IDE offers an IntelliSense list of possible values fromRuleTemplates
./EDIT:
Since this is a feature that relies on the IDE, it's hard to show how this looks when you use it but I'll just use a screenshot:
Completion list in action http://page.mi.fu-berlin.de/krudolph/stuff/completionlist.png
In fact, the IntelliSense is 100% identical to what you get when using an
Enum
.