In vb.net you can actually compare strings with =
. Even though String
is a reference type, in vb.net =
on String
has been redefined to do a case-sensitive comparison of contents of the two strings.
You can test this with the following code. Note that I have taken one of the values from user input to ensure that the compiler cannot use the same reference for the two variables like the Java compiler would if variables were defined from the same string Literal. Run the program, type "This" and press <Enter>.
Sub Main()
Dim a As String = New String("This")
Dim b As String
b = Console.ReadLine()
If a = b Then
Console.WriteLine("They are equal")
Else
Console.WriteLine("Not equal")
End If
Console.ReadLine()
End Sub