Donate

Copy Single Element Of An array To Another Array Without Using Loop In C# And VB.NET

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 destinationArray As Integer() = New Integer(1) {}
Array.Copy(sourceArray, 3, destinationArray, 0, 1)

Comments

Donate

Popular Posts From This Blog

WPF CRUD Application Using DataGrid, MVVM Pattern, Entity Framework, And C#.NET

TypeScript Error Or Bug: The term 'tsc' is not recognized as the name of a cmdlet, function, script file, or operable program.

Invalid nested tag div found, expected closing tag input