var sourceArray = new byte[] { 1, 2, 3, 4, 5 }; var sourceSegment = new ArraySegment(sourceArray, 0, 3); var destinationArray = new byte[3]; var destinationSegment = new ArraySegment (destinationArray); sourceSegment.CopyTo(destinationSegment); // Result: destinationArray = { 1, 2, 3 }
var sourceArray = new int[] { 1, 2, 3, 4, 5 }; var sourceSegment = new ArraySegmentIn this example, we create an ArraySegment(sourceArray, 1, 3); var destinationList = new List (); sourceSegment.CopyTo(destinationArray, 0); // Result: destinationList = { 2, 3, 4 }