Tutorial by Examples

To avoid verbose null checking, the ?. operator has been introduced in the language. The old verbose syntax: If myObject IsNot Nothing AndAlso myObject.Value >= 10 Then Can be now replaced by the concise: If myObject?.Value >= 10 Then The ? operator is particularly powerful when you...
The NameOf operator resolves namespaces, types, variables and member names at compile time and replaces them with the string equivalent. One of the use cases: Sub MySub(variable As String) If variable Is Nothing Then Throw New ArgumentNullException("variable") End Sub The old sy...
This new feature makes the string concatenation more readable. This syntax will be compiled to its equivalent String.Format call. Without string interpolation: String.Format("Hello, {0}", name) With string interpolation: $"Hello, {name}" The two lines are equivalent and ...
Read-only properties were always possible in VB.NET in this format: Public Class Foo Private _MyProperty As String = "Bar" Public ReadOnly Property MyProperty As String Get Return _MyProperty End Get End Property End Class The new version of Visual Basi...
Similar to partial classes the new version of Visual Basic is now able to handle partial modules and partial interfaces. The syntax and behaviour is exactly the same as it would be for partial classes. A partial module example: Partial Module Module1 Sub Main() Console.Write("Ping -&g...
VB now allows string literals that split over multiple lines. Old syntax: Dim text As String = "Line1" & Environment.NewLine & "Line2" New syntax: Dim text As String = "Line 1 Line 2"
#Region directive can now be placed inside methods and can even span over methods, classes and modules. #Region "A Region Spanning A Class and Ending Inside Of A Method In A Module" Public Class FakeClass 'Nothing to see here, just a fake class. End Class Module Extensi...
VB 14.0 introduces the ability to add comments after implicit line continuation. Dim number = From c As Char 'Comment In "dj58kwd92n4" 'Comment Where Char.IsNumber(c) 'Comment Select c 'Comment
During coding, unexpected errors do arise frequently enough, which requires debugging and testing. But sometimes the errors are indeed expected and to bypass it, there is the Try..Catch..Throw..Finally..End Try block. To manage an error correctly, the code is put into a Try..Catch block, whereby th...

Page 1 of 1