Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VB.NET - What does ":=" do?

I can't find any information online or under the Operator documentation, but I've seen this ":=" used a few times in VB.NET and I can't work out what it does.

like image 450
Lou Avatar asked Jun 28 '13 15:06

Lou


1 Answers

It's used for named parameters (ht to SLaks for the link) in a method call and is usually used with optional arguments.

It's usually useful for calling Word or Excel methods through ActiveX calls, where there are an awful lot of optional arguments, most of which are never used.

Example

Private Function test(arg1 As Integer, arg2 As Integer) As Boolean
    Debug.WriteLine("{0}  {1}", arg1, arg2)
    Return True
End Function

These two will both produce the same result

test(arg2:=2, arg1:=1)

test(1, 2)

Debug output

1  2

1  2
like image 112
Raghav Sood Avatar answered Oct 08 '22 03:10

Raghav Sood