Reputation: 24699
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?
Upvotes: 0
Views: 272
Reputation: 942438
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
Upvotes: 1