VB.NET := Operator
Asked Answered
U

3

7

What does the following mean?

Class.Function(variable := 1 + 1)

What is this operator called, and what does it do?

Uchish answered 15/10, 2008 at 14:17 Comment(0)
A
11

It is used to assign optional variables, without assigning the previous ones.

sub test(optional a as string = "", optional b as string = "")
   msgbox(a & b)
end sub

you can now do

test(b:= "blaat")
'in stead of
test("", "blaat")
Aircraftman answered 15/10, 2008 at 14:29 Comment(1)
I also use it sometimes for required variables. For example if I have a function that takes multiple boolean flags (the horrors!) then I can do something like DoTheThing(doItFast := True, doItNow := True...) so that it's clear what flags I'm setting (as opposed to DoTheThing(True, True, False, True, False, False, False) :P)Simple
H
0

It assigns the optional parameter "variable" the value 2.

Hanforrd answered 15/10, 2008 at 14:22 Comment(0)
C
0

VB.NET supports this syntax for named (optional) parameters in method calls. This particular syntax informs Class.Function that its parameter variable is to be set to 2 (1 + 1).

Culhert answered 15/10, 2008 at 14:32 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.