Hi,
What MSFT example do you mean?
It's basically the same thing as Copy except it ensures that the operation
is atomic, so that in the case of an exception it will leave the destination
array in the state that it was in before the operation was attempted.
Other, more subtle differences between the Copy and the ConstrainedCopy
methods are explained in the following documentation:
Array.ConstrainedCopy Methodhttp://msdn2.microsoft.com/en-us/library/system.array.constrainedcopy...
Here's a simple example:
int[] array1 = new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
int[] array2 = new int[20];
Array.ConstrainedCopy(array1, 0, array2, 5, 10);
for (int i = 0; i < array2.Length; i++)
{
Console.WriteLine("{0}: {1}", i, array2
);
}Output:
0: 0
1: 0
2: 0
3: 0
4: 0
5: 1
6: 2
7: 3
8: 4
9: 5
10: 6
11: 7
12: 8
13: 9
14: 10
15: 0
16: 0
17: 0
18: 0
19: 0
--
Dave Sextonhttp://davesexton.com/blog
Can anyone show me an example of how to use the Array.ConstrainedCopy
method. The MSFT example is worthless.- Hide quoted text -- Show quoted text -