How to clone Array within a Class ? ?? ?

Please HEEEEEELLP

Unbelievable :

I have a class :

Public Class ClassLine

    Private m_Name As String
    Private m_ArrayY As Double()

   Public Function ShallowCopy() As ClassLine   ' this lets to clone the details of a class, but NOT a REFERENCE !
        Return Me.MemberwiseClone
    End Function

end class

(See this to understand ShallowCopy:
http://www.larkware.com/Articles/CloninginVB.NET.html)


Well...If I use this on the form:


Dim L1 As ClassLine = L.ShallowCopy

All is cloned ok, except the ARRAY !

That's it :

If I have : L.name= "Rufus"
and I have cloned on L1, after do the shallow copy I can do: L.name="pipo", and L1.name is still with : L.name= "Rufus"

But is I modify the Array, the data is also modified on L1 .... WHY ? ? ?

How can I solve it  ? ?

I tried this :


L1.ArrayY = L.ArrayY
L1.Name = L.Name

and this :

 Dim ArrayTemp() As Double = L.ArrayY
        For i = 0 To UBound(L.ArrayY)
            ArrayTemp(i) = L.ArrayY(i)
        Next

        L1.ArrayY = ArrayTemp

But still the same reference....

Any ideas ? ? ?













LVL 1
franklinanAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

franklinanAuthor Commented:
Hey ! I achieved that :

This works :

Dim ArrayTemp() As Double
        ReDim ArrayTemp(UBound(L.ArrayY))
        For i = 0 To UBound(L.ArrayY)
            ArrayTemp(i) = L.ArrayY(i)
        Next

        L1.ArrayY = ArrayTemp

But...any idea of doing this more elegant = ? ?? ??

Bye !!


0
bruintjeCommented:
Hello franklinan,

you could look at

ArrayTemp = L.ArrayY.Clone

source: http://www.knowdotnet.com/articles/arrays.html

hope this helps a bit
bruintje
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
franklinanAuthor Commented:
Perfect ! Really elegant ....

I'll give you the points ..._I solved the problem myself but this post really deserves the points ...
0
bruintjeCommented:
thanks :)
 
asking questions really helps to mind jog the brain :)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.