What is the: = "operator in (VB) .NET, or what is it good for?
You can use the: = syntax to assign Sub or Function parameters by name rather than strictly by position. For example:
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
TestRoutine(Y:="TestString", X:=12)
End Sub
Private Sub TestRoutine(ByVal X As Long, Optional Y As String = "")
' Do something with X and Y here... '
End Sub
End Class
Note that TestRoutine specifies X as the first parameter and Y as the second, but calls to Form1_Load have them in reverse order, naming each parameter with the: = operator.
Here's a link to an MSDN article on the topic:
http://msdn.microsoft.com/en-us/library/51wfzyw0.aspx
I don't see this used very often, except for the VBA macros created by the Excel macro that uses it a lot .
source to share
This is really useful when there are several optional parameters - you can see a lot of code calling in office object models - Word, Excel, etc. When you have 40 parameters, of which 37 of them are optional, and you want to set values ββfor parameters 34 and 40, a clearer lot : = than for a function call ("new", "settings", 1 ,,,, ,,,,,,,,,,, 43, 2 ,,, 7)
I wanted to make this comment on JeffK, but I miss the reputation.
source to share
VB uses this operator to assign attribute values:
http://www.ondotnet.com/pub/a/dotnet/excerpt/vbnut_8/index1.html
source to share