Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does a := (colon equals) in VB.NET do? [duplicate]

Possible Duplicate:
What is the use of the := syntax?

I've tried hunting down the MDSN documentation for := in VB.NET as well as scoured Google only to be linked to a dead MSDN page... What would the purpose of := be?

like image 334
Andy Danger Gagne Avatar asked Jul 01 '11 13:07

Andy Danger Gagne


1 Answers

It strongly names arguments, allowing you to call a method with arguments in an order other than that specified in the method definition.

For example:

sub foo (byval x As Long, byval y As Long)
   debug.print (String.Format("{0}, {1}", x.ToString, y.ToString))
end Function

can be called with the order of the arguments reversed by using their names:

foo (y:=999, x:=111)

prints:

111, 999

This is especially useful when you have a long list of optional arguments, you only want to specify a few of them, and those that you want to specify are not the first ones.

like image 108
Alex K. Avatar answered Oct 14 '22 10:10

Alex K.