Search code examples
vb.netsyntaxfunctionlanguage-featuresbyref

What is the use of the := syntax?


I'm a C# developer working on a VB.NET project, and VS keeps trying to get me to use the := thingie when I call a function with a ByRef parameter like so:

While reader.Read()
HydrateBookFromReader(reader:=???)

the HydrateBookFromReader function has the following signature:

Public Function HydrateBookFromReader(ByRef reader As SqlDataReader) As Book

Why does intellisense keep insisting that I use that := construction, and what is it for?


Solution

  • In VB, the := is used in specifying named parameters.

    Contact(Address:="2020 Palm Ave", Name:="Peter Evans")
    

    This is especially useful for specifying optional parameters.