Search code examples
vb.netoptional-variables

VB.NET := Operator


What does the following mean?

Class.Function(variable := 1 + 1)

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


Solution

  • 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")