Advanced literals for Visual Studio
As soon as I learned that Microsoft had opened a channel at uservoice.com so that we (developers) could suggest new/improved features for the upcoming Visual Studio 11 (now known as Visual Studio 2012), the first thing I wanted to suggest was the ability to easily handle numbers of different bases, natively.
Regardless of the language, which in this case is VB, consider the beauty and simplicity of the following code:
Dim decNum = 726d Dim binNum = 1001b Dim hexNum = f7a1h Dim octNum = 167o
Here we are initializing several numeric variables which obtain their value based on a compiler automated procedure that converts the number into an unsigned integer from a base predefined by a suffix letter that conditions the conversion to the appropriate base type.
Then we would require simple ToXXX() functions (as well as “CType “, “DirectCast” or “as”, in C#, support) in order to easily and specifically convert from one type to another without requiring a string intermediate, as we do now… which, frankly, sucks!
For this to work, the Framework should implement distinct types for each base (of course, only for the most common ones) and derive them all from UInt (and make UInt inheritable) so that it’s easy to perform simple type castings between them and allows us to extend it to support any custom base.