views:

17

answers:

2

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?

+2  A: 

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

DJ Quimby
+1  A: 

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

Andrey