开发者

What does := mean in vb.net?

We have this method call:

SendAck(AppData:=AppData, Status:=Status, StatusMessage:=StatusMessage, IsApplication:=IsApplication)

And here is the definition:

Private Sub SendAck(ByVal AppData As XDocument, ByVal Status As Boolean, ByVal St开发者_如何学运维atusMessage As String, ByVal IsApplication As Boolean)

Why does the call have the parameters with the ":=". I'm just curious.


The ":=" in VB.Net is used to pass a function argument by name. The default is by position. It allows for parameters to be called in any order and determines the positioning based on name matches.

For example

Sub Example(ByVal param1 as Integer, ByVal param2 As Integer) 
  Console.WriteLine("{0} - {1}", param1, param2)
End Sub

Example(param2:=42, param1:=1) ' Prints "1 - 42"
Example(42, 1)                 ' Prints "42 - 1"


That syntax is using named arguments; Specifying the names of the parameters being set before the := then the value after. Doing that can enable you to skip parameters or do them in different order.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜