Introduction
Exciting times are ahead, and I personally cannot wait for the new version of Visual Basic to be released. Today, I will explain a few new features in Visual Basic 14 and Windows 10.
Multiline String Literals
This is not my favorite feature, but it is new. You will be able to split string literals over multiple lines. Here is an example:
Dim strStringVariable = "Hello Hannes! How are you today?"
Now, for a guy who has used VB since forever, I am not entirely happy with this. I still love my concatenation…
String Interpolation
Now this I love!
We, as VB developers, have been accustomed to using the placeholders expression in our strings. With String Interpolation, using an expression inside a string has become much easier. Here is an example:
'string with expressions Dim strName = String.Format("hello {0} {1}", _ strName, strSurname) 'string interpolation Dim s = $"hello {strName} {strSurname}"
Comments Allowed in More Places
In olden days, it was impossible to add a comment inside a LINQ expression and in-Line continuations. Now, this is impossible no more because the following will be allowed:
Dim arrEmployees = {"Hannes", 'Me "Ella", 'My wife "Kay" 'My daughter } 'loop through employees Dim EmployeeAdresses = From i In arrEmployees Let EmployeeAdress = Lookup(i) 'lookup Select i, EmployeeAdress
Year-first Date Literals
This finally will reduce the ambiguity between writing months first, or days first inside a date. Here is an example:
Dim dtDate1 = #2015-04-19# ' yyyy-MM-dd, April 9th 2015 Dim dtDate2 = #2015/04/19#
‘#Region’ Directives Inside Method Bodies
Another feature that I have begged for a long time is the ability to include a Region directive inside a method. Here is how you would be able to implement it:
Function ReturnName(strName As String, _ strSurname As String) Try 'Method Body here #Region "In case of Error" Catch ex As Exception 'Error code here #End Region End Function
The ?. Operator
Having to check for NULL values, or values that are Nothing, has always been a pain for me, and I believe many a fellow VB developer. This operator makes it easy to check for null values in objects. Here is an example of its implementation:
'Old Dim EmpObject = Employee.Name Dim Result = If(EmpObject IsNot Nothing, _ Employee.Name.Surname, Nothing) 'New Dim x = Employee.Name?.Surname
ReadOnly Auto-implemented Properties
You now can have ReadOnly auto-implemented properties. Here is an example of its implementation:
Class Employee Public ReadOnly Property Name _ As String = "" Public ReadOnly Property Surname As String Sub New(strName As String) Me.Name = strName End Sub End Class
Smart Name Resolution
There will be less ambiguity for some namespace methods. Sometimes, it is very irritating when you try to do something as simple as creating a thread, and then the compiler tells you that a certain method is ambiguous. With smart name resolution, the compiler will be able to automatically detect which namespace method gets called from your code.
Partial Module and Interface Declarations
VB used to allow only Partial on classes and structures. Now, it is allowed on modules and interfaces as well:
Partial Module Extensions End Module Partial Interface IDirectory End Interface
Structures Allow Sub New()
VB will allow you to declare a parameterless constructor for a struct.
Structure Structure1 Public Age As Integer Sub New() Age = 37 End Sub End Structure
Conclusion
These are just some of the new and exciting features to expect. For a full list, have a look here:
https://roslyn.codeplex.com/discussions/571884
Thank you for reading my article. I hope you have enjoyed it. Until we meet again, cheers!