0

In VB.NET, I am looking at a line of code that passes the following value to a procedure that defines the parameter as type "object."

New Object() {gClient.ContactManager, LyncUri}

Here's the complete relevant code

Dim gClient As Microsoft.Lync.Model.LyncClient
gClient = Microsoft.Lync.Model.LyncClient.GetClient()

    gClient.ContactManager.BeginSearch(LyncUri,
        Ly.SearchProviders.GlobalAddressList,
        Ly.SearchFields.EmailAddresses,
        Ly.SearchOptions.IncludeContactsWithoutSipOrTelUri,
        1,
        AddressOf SearchCallback,
        New Object() {gClient.ContactManager, LyncUri})

and procedure definition

Public Function BeginSearch(searchString As String, providers As Microsoft.Lync.Model.SearchProviders, searchFields As Microsoft.Lync.Model.SearchFields, searchOptions As Microsoft.Lync.Model.SearchOptions, maxResults As UInteger, contactsAndGroupsCallback As System.AsyncCallback, state As Object) As System.IAsyncResult

I have seen object initializer code that initializes properties of an object by assigning properties values within the brackets using the syntax format of {property1 = value1, property2 = value}, for example but what exactly is the above code doing?

1
  • 2
    It creates an array. Example: Dim obj As String() = New String() {"MyObj1", "MyObj2", "MyObj2"}. Commented Dec 14, 2013 at 16:17

1 Answer 1

1

New Object() creates an array of objects. What's between the { braces } is what initializes the elements of the array. Very convenient syntax sugar for the verbose:

dim arr = New Object(1)
arr(0) = gClient.ContactManager
arr(1) = LyncUri
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.