我尝试将 vb.net 代码转换为 c#,如下 VB.NET
Dim _obj As Object = _srv.GetData(_criteria)
If _obj IsNot Nothing Then
For Each Comp As ComponentItem In DirectCast(DirectCast(_obj("ComponentInformation"), Result).Output, List(Of ComponentItem))
_lstComp.Add(New Core.Component() With {.ComponentID = Comp.BusinessUnitID, .ComponentName = Comp.BusinessUnitName})
Next
End If
C#
object obj = srv.GetData(criteria);
if (obj != null)
{
foreach (ComponentItem comp in (List<ComponentItem>)((Result)obj("ComponentInformation")).Output)
{
lstComp.Add(new Component
{
ComponentId = comp.BusinessUnitID,
ComponentName = comp.BusinessUnitName
});
}
}
转换代码后我得到一个错误obj' is a 'variable' but is used like a 'method'如何解决这个错误?