J# 集合到 VB .NET 集合

发布于 2024-10-09 00:09:08 字数 667 浏览 5 评论 0原文

我有一系列返回 J# 数据类型的 API 调用。我已经能够很好地转换大多数数据类型(整数、布尔值、双精度值、浮点值等)。

我现在需要做的是将 java.Util.Collection 转换为 VB .NET 集合(ArrayList?)

这是我的尝试:

Public Function MakeDotNETCollection(ByVal javaCol As java.util.Collection) As Collection

    Dim dotNetCol As Collection

    If Not javaCol Is Nothing Then
      dotNetCol = New Collection

      Dim it As IEnumerator = javaCol.iterator()

      For Each it In CType(javaCol, Collection)
        dotNetCol.Add(it.Current)
      Next it

    End If

    Return dotNetCol
  End Function

我不断收到运行时错误“无法将类型为 'AbstractListlistIterator' 的对象转换为类型为 'System. Collections.IEnumerator 有什么想法吗?

I have a series of API calls that are returning J# data types. I have been able to convert most of the data types (Integer, Boolean, Double, Float, etc) just fine.

What I need to do now is convert a java.Util.Collection to a VB .NET collection (ArrayList?)

Here is my attempt:

Public Function MakeDotNETCollection(ByVal javaCol As java.util.Collection) As Collection

    Dim dotNetCol As Collection

    If Not javaCol Is Nothing Then
      dotNetCol = New Collection

      Dim it As IEnumerator = javaCol.iterator()

      For Each it In CType(javaCol, Collection)
        dotNetCol.Add(it.Current)
      Next it

    End If

    Return dotNetCol
  End Function

I keep getting a runtime error "Unable to cast object of type 'AbstractListlistIterator' to type 'System.Collections.IEnumerator. Any ideas?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

嘿哥们儿 2024-10-16 00:09:08

未经测试,但应该可以工作:

Public Function MakeDotNETCollection(ByVal javaCol As java.util.Collection) As Collection

  Dim dotNetCol As Collection

  If Not javaCol Is Nothing Then
    dotNetCol = New Collection

    Dim it As java.util.Iterator = javaCol.iterator()

    While it.HasNext()
      dotNetCol.Add(it.next())
    End While

  End If

  Return dotNetCol

End Function

Not tested, but should work:

Public Function MakeDotNETCollection(ByVal javaCol As java.util.Collection) As Collection

  Dim dotNetCol As Collection

  If Not javaCol Is Nothing Then
    dotNetCol = New Collection

    Dim it As java.util.Iterator = javaCol.iterator()

    While it.HasNext()
      dotNetCol.Add(it.next())
    End While

  End If

  Return dotNetCol

End Function
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文