将一个结构数组分配给另一个具有相同结构的数组

发布于 2024-09-26 19:08:32 字数 386 浏览 1 评论 0原文

在 Vb.net 中,我试图将一个结构数组分配给另一个具有相同结构的数组,

  Dim info() As assemblyInfo
  Dim info2() As assemblyInfo

    Structure assemblyInfo
        Dim Name As String
        Dim ClassTpys() As ClassTyp
    End Structure

Private Sub test()

info2 = info

ifo 中的任何更改都会反映在 info2 中,此 allocatemnet 是通过Ref 发生的。

我不希望信息的任何更改反映在 info2 中,反之亦然,在分配后,我怎样才能实现这一目标?

In Vb.net I am trying to assign an array of structure to another array of same structure

  Dim info() As assemblyInfo
  Dim info2() As assemblyInfo

    Structure assemblyInfo
        Dim Name As String
        Dim ClassTpys() As ClassTyp
    End Structure

Private Sub test()

info2 = info

any change in ifo gets reflected in info2, this assignmnet is happening byRef.

I don't want any change in info to get reflected in info2 and vice-versa, after the assignment, how can I achieve this?

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

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

发布评论

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

评论(2

多像笑话 2024-10-03 19:08:32

发生这种情况是因为 info2=info 只是将 info 的引用分配给 info2。尝试 info.CopyTo(info2, 0)

This is happening because info2=info is just assigning the reference of info to info2. Try info.CopyTo(info2, 0)

美人骨 2024-10-03 19:08:32

数组是引用类型,因此当您分配它时,您实际上分配了对它的引用。
您需要 Array.Copy 方法 http://msdn。 microsoft.com/en-us/library/k4yx47a1.aspx

Array is reference type so when you assign it you assign reference to it actually.
You need Array.Copy method http://msdn.microsoft.com/en-us/library/k4yx47a1.aspx

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