Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 758
Josh E Avatar asked May 23 '09 20:05

Josh E


People also ask

What is := used for?

The colon equal sign := is used to set the value of an parameter (argument) for a property or method.

What Is syntax example?

Syntax is the order or arrangement of words and phrases to form proper sentences. The most basic syntax follows a subject + verb + direct object formula. That is, "Jillian hit the ball." Syntax allows us to understand that we wouldn't write, "Hit Jillian the ball."

What is language syntax?

The syntax of a language describes the form of a valid program, but does not provide any information about the meaning of the program or the results of executing that program. The meaning given to a combination of symbols is handled by semantics (either formal or hard-coded in a reference implementation).


2 Answers

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.

like image 186
DOK Avatar answered Sep 22 '22 00:09

DOK


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

It's important to note that IntelliSense doesn't insist, it proposes. Using it in your case wouldn't make sense … this feature is primarily used for very long parameter lists with many optional parameters, of which you only want to pass, say, the last one. It's useful when working with Microsoft Office Interop.

Also (since you mention it in your tags): this has got nothing to do with ByRef. ByRef is equivalent to ref and out in C#, i.e. it allows the method to manipulate the parameter itself.

like image 23
Konrad Rudolph Avatar answered Sep 21 '22 00:09

Konrad Rudolph