I’ve seen this before, but I’ve never really been interested in its purpose until now. Take a look at the following two examples (oh, this is all in VB.net btw):
Example 1:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Using nFD As New FontDialog
If nFD.ShowDialog = Windows.Forms.DialogResult.OK Then
LoadFont(_font:=nFD.Font)
End If
End Using
End Sub
Private Sub LoadFont(ByVal _font As Font)
MsgBox(_font.Name)
End Sub
Example 2
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Using nFD As New FontDialog
If nFD.ShowDialog = Windows.Forms.DialogResult.OK Then
LoadFont(nFD.Font)
End If
End Using
End Sub
Private Sub LoadFont(ByVal _font As Font)
MsgBox(_font.Name)
End Sub
Both result in the same thing, the main thing you might want to pay attention to is where I set the argument. What is the purpose of the := when setting the argument. I’m assuming it has some kind of more important use than what I just experimented with, but I can’t Google it because Google doesn’t like symbols.
Named arguments. Since VB.NET allows optional arguments, you may occasionally want to pass only the second or third argument, leaving the preceding ones at their defaults. Using named arguments, you can. Another thing you can do is pass arguments in a different order. And finally, when a function takes a lot of arguments, passing them named-style may help readability.