What is the difference between = and: =

advertisements

I'm sure this is straightforward but I cannot find the correct string to get a google result. In VB.NET what is the difference between = (equals sign) and := (colon followed by equals sign)?


The := operator is used to pass arguments by name in VB.Net. For instance take the following code

Sub Foo(p1 As integer, p2 As String)
  ..
End Sub

Sub Test()
  Foo(p2:="foo",p1:=42)
End Sub

If you look strictly at the types involved here I've passed the values out of order. But Because I bound the arguments by name using :=, the compiler will properly pass the values.

The = operator depends on the context in VB.Net. It can be either an assignment or comparison operator. For instance

Dim x = 42 ' Assignment
if x = 36 Then
 'Comparison above
End if