得到一个;类型错误“;在vb.net中由C转换而来的代码#
我在VB.Net 2010中有这段代码,我在New()上遇到了一个“类型错误” 此代码是从C#转换而来的 我做错了什么得到一个;类型错误“;在vb.net中由C转换而来的代码#,vb.net,visual-studio-2010,Vb.net,Visual Studio 2010,我在VB.Net 2010中有这段代码,我在New()上遇到了一个“类型错误” 此代码是从C#转换而来的 我做错了什么 Public Function CredentialGet(ByVal sKey As String, ByRef sCred As String) Dim sCredential As Element.Credential sCredential = apiclient.SearchCredentials(sSoftwareKey, SessionID,
Public Function CredentialGet(ByVal sKey As String, ByRef sCred As String)
Dim sCredential As Element.Credential
sCredential = apiclient.SearchCredentials(sSoftwareKey, SessionID,
New() {New Element.SearchTerm() With {.FilterKey = "APK", .Value = sKey}})
sCred = sCredential.CredentialID
End Function
新的什么?您缺少一个对象名称。您现在正在传入一个匿名对象。删除匿名类型的括号。VB.Net在该上下文中不使用它们,而是查找带有关键字的
。函数应该返回一个值。您不返回任何内容,因此请使用Sub:
Public Sub CredentialGet(ByVal Key As String, ByRef Cred As String)
Dim Credential As Element.Credential
Credential = apiclient.SearchCredentials(sSoftwareKey, SessionID, _
New With {New Element.SearchTerm() With {.FilterKey = "APK", .Value = Key}})
Cred = Credential.CredentialID
End Sub
我也质疑这个设计。最好返回一个字符串:
Public Function CredentialGet(ByVal Key As String) As String
Return apiclient.SearchCredentials(sSoftwareKey, SessionID, _
New With {New Element.SearchTerm() With {.FilterKey = "APK", .Value = Key}}).CredentialID
End Function