Click to Rate and Give Feedback
MSDN
MSDN Library
Visual Studio 2005
Visual Studio
Visual Basic
Operators
 AddressOf Operator

  Switch on low bandwidth view
This page is specific to
Microsoft Visual Studio 2005/.NET Framework 2.0

Other versions are also available for the following:
Visual Basic Language Reference 
AddressOf Operator 

Creates a procedure delegate instance that references the specific procedure.

AddressOf procedurename
procedurename

Required. Specifies the procedure to be referenced by the newly created procedure delegate.

The AddressOf operator creates a function delegate that points to the function specified by procedurename. When the specified procedure is an instance method then the function delegate refers to both the instance and the method. Then, when the function delegate is invoked the specified method of the specified instance is called.

The AddressOf operator can be used as the operand of a delegate constructor or it can be used in a context in which the type of the delegate can be determined by the compiler.

This example uses the AddressOf operator to designate a delegate to handle the Click event of a button.

Visual Basic
' Add the following line to Sub Form1_Load().
AddHandler Button1.Click, AddressOf Button1_Click

The following example uses the AddressOf operator to designate the startup function for a thread.

Visual Basic
Public Sub CountSheep()
    Dim i As Integer = 1 ' Sheep do not count from 0.
    Do While (True) ' Endless loop.
        Console.WriteLine("Sheep " & i & " Baah")
        i = i + 1
        System.Threading.Thread.Sleep(1000) 'Wait 1 second.
    Loop
End Sub

Sub UseThread()
    Dim t As New System.Threading.Thread(AddressOf CountSheep)
    t.Start()
End Sub
Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Processing
© 2009 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker