Click here to Skip to main content
       

.NET Framework

 
QuestionArray of Double - Shallow vs. Deep Cloning? PinmemberMike-MadBadger5-Oct-12 7:01 
So I'm quite comfortable with shallow and deep cloning for value and reference types but want to check how this plays out for an array of a value type.
 
I have a 2D array of double and since the array contains value types I think the Array.Clone method (whilst only guaranteeing shallow copies) will give a deep copy in this instance. Am I right?
Private _matrix as double(,)
 
Public Function CopyToArray() as Double(,)
    Return Me._matrix.Clone()
End Fucntion
 
Public Function Copy() As Matrix
    Return New Matrix(Me.CopyToArray())
End Function
 
Public Sub New(ByVal array As Double(,))
    Me._matrix = array
End Sub
The constructor assumes that the user wants to assign the 2D array of double(,) they have already created to the new matrix instance and hence doesn't use Array.Clone (and since the array is a class and is therefore a reference type, ByVal essentially has no meaning in this context). Did I get that bit right?
 
Thanks,
Mike
AnswerRe: Array of Double - Shallow vs. Deep Cloning? PinmemberEddy Vluggen5-Oct-12 12:25 
GeneralRe: Array of Double - Shallow vs. Deep Cloning? PinmemberMike-MadBadger7-Oct-12 9:56 
AnswerRe: Array of Double - Shallow vs. Deep Cloning? PinmemberEddy Vluggen8-Oct-12 0:39 
GeneralRe: Array of Double - Shallow vs. Deep Cloning? PinmemberMike-MadBadger9-Oct-12 23:04 
GeneralRe: Array of Double - Shallow vs. Deep Cloning? PinmemberEddy Vluggen10-Oct-12 1:22 
GeneralOT PinmemberMike-MadBadger10-Oct-12 2:23 
GeneralRe: OT PinmemberEddy Vluggen10-Oct-12 9:00 
GeneralRe: Array of Double - Shallow vs. Deep Cloning? Pinmemberdojohansen10-Oct-12 5:36 
GeneralRe: Array of Double - Shallow vs. Deep Cloning? PinmemberEddy Vluggen10-Oct-12 9:09 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.


Advertise | Privacy | Mobile
Web02 | 2.8.140421.2 | Last Updated 23 Apr 2014
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Use
Layout: fixed | fluid