Wednesday, April 20, 2016

Copy single element of an array to another array without using loop

Simple solution is to use Array.Copy() method.
C# Code
1
2
3
int[] sourceArray = {1,2,3,4,5,6,7,8,9,10};
int[] destinationArray = new int[1];
Array.Copy(sourceArray,3,destinationArray,0,1);

VB.NET Code
1
2
3
Dim sourceArray As Integer() = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}
Dim b As Integer() = New Integer(1) {}
Array.Copy(sourceArray, 3, destinationArray, 0, 1)

0 comments:

Post a Comment