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

I can not find any information on the Internet or under the documentation of the Operator, but I saw this ": =" several times in VB.NET, and I can not understand what it is doing.

+6
source share
3 answers

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

This is usually useful for invoking Word or Excel methods using ActiveX calls, where there are many 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 give the same result.

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

Debug output

 1 2 1 2 
+10
source

This is used for named parameters :

 MyMethod(parameterName := value) 
+5
source

This is the use of "named parameters", so you can use the parameters in the function in any order, specifying the function name of each of them. :)

+3
source

Source: https://habr.com/ru/post/948334/


All Articles