Unless in Visual Basic .NET

Find this useful? Support us: Star on GitHub 6
Category: Conditional | Language: Visual Basic .NET

In Visual Basic .NET, unless is not a reserved keyword. However, you can achieve the same functionality as unless using the Not operator with an If statement.

The syntax would be:
``vb.net
If Not condition Then
' statements to execute if the condition is False
End If


Here is an example that demonstrates the use of the Not operator with an If statement to achieve the same functionality as unless:
vb.net
Dim grade As Integer = 80

If Not grade >= 60 Then
Console.WriteLine("Student has failed the course.")
End If

In this example, unless would have been used as follows: 
vb.net
Unless grade >= 60 Then
Console.WriteLine("Student has failed the course.")
End If
``
However, as previously mentioned, unless is not a reserved keyword in Visual Basic .NET.