在VB.NET中,我正在查看一行代码,该代码将以下值传递给将参数定义为“object”类型的过程。
New Object() {gClient.ContactManager, LyncUri}
这是完整的相关代码
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})
和程序定义
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
我见过对象初始化代码,它通过使用{property1 = value1,property2 = value}的语法格式在括号内指定属性值来初始化对象的属性,例如,上面的代码到底是做什么的?
答案 0 :(得分:1)
New Object()
创建一个数组对象。 {braces}之间的内容是初始化数组的元素。详细的语法糖非常方便:
dim arr = New Object(1)
arr(0) = gClient.ContactManager
arr(1) = LyncUri