I have defined 2 classes and some objects like these:
public class MyClass
{
public int[] numbers { get; set; }
//some other properties
}
public class DemoClass
{
//some other properties
public int[] numbers { get; set; }
//some other properties
}
var myObject= new MyClass();
var sourceObject= new DemoClass{
numbers={1,2,3}
//other properties
}
Now, I want to copy the array of sourceObject into the array of myObject. What is the best approach?
myObject.numbers= sourceObject.numbers;
or
myObject.numbers= (int[])sourceObject.numbers.Clone();
.ToArray()... But really it mostly taste choice... and a bit of whether you actually need a "copy" (as the title says) or the same reference as the sample code in the post shows.sourceObject.numbers.myObject.numbers= sourceObject.numbers.ToArray();, too.