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?
Consider the following event declaration
In C#, you can check for event subscribers by using the following syntax:
However, the VB.NET compiler does not support this. It actually creates a hidden private member field which is not visible in IntelliSense:
More Information:
http://jelle.druyts.net/2003/05/09/BehindTheScenesOfEventsInVBNET.aspx http://blogs.msdn.com/vbteam/archive/2009/09/25/testing-events-for-nothing-null-doug-rothaus.aspx
There are a couple of answers about XML Literals, but not about this specific case:
You can use XML Literals to enclose string literals that would otherwise need to be escaped. String literals that contain double-quotes, for instance.
Instead of this:
You can do this:
This is especially useful if you're testing a literal for CSV parsing:
(You don't have to use the
<string>
tag, of course; you can use any tag you like.)If you need a variable name to match that of a keyword, enclose it with brackets. Not nec. the best practice though - but it can be used wisely.
e.g.
e.g. Example from comments(@Pondidum):
Optional Parameters
Optionals are so much easier than creating a new overloads, such as :
In vb there is a different between these operators:
/
isDouble
\
isInteger
ignoring the remainderThe Using statement is new as of VB 8, C# had it from the start. It calls dispose automagically for you.
E.g.