Create elements from one array to another array
Public Class SamplesArray2
Public Shared Sub Main()
Dim myArrayZero As Array = Array.CreateInstance(GetType(String), 3)
myArrayZero.SetValue("zero", 0)
myArrayZero.SetValue("one", 1)
PrintIndexAndValues(myArrayZero)
Dim myArrLen As Integer() = {4}
Dim myArrLow As Integer() = {2}
Dim myArrayTwo As Array = Array.CreateInstance(GetType(String), myArrLen, myArrLow)
myArrayTwo.SetValue("two", 2)
myArrayTwo.SetValue("three", 3)
myArrayTwo.SetValue("four", 4)
myArrayTwo.SetValue("five", 5)
PrintIndexAndValues(myArrayTwo)
myArrayZero.CopyTo(myArrayTwo, 3)
PrintIndexAndValues(myArrayTwo)
End Sub
Public Shared Sub PrintIndexAndValues(myArray As Array)
Dim i As Integer
For i = myArray.GetLowerBound(0) To myArray.GetUpperBound(0)
Console.WriteLine(myArray.GetValue(i))
Next i
End Sub
End Class
Related examples in the same category
| 1. | Creates a one-dimensional Array of the specified Type and length, with zero-based indexing. | | |
| 2. | Creates a two-dimensional Array of the specified Type and dimension lengths, with zero-based indexing. | | |
| 3. | Creates a three-dimensional Array of the specified Type and dimension lengths, with zero-based indexing. | | |
| 4. | Creates a multidimensional Array of the specified Type and dimension lengths, with zero-based indexing. | | |
| 5. | Creates a multidimensional Array of the specified Type and dimension lengths, with the specified lower bounds. | | |
| 6. | Bounded array Example | |  |
| 7. | For Each loops through Array | |  |
| 8. | Two ways to loop through Array | |  |
| 9. | A simple class to store in the array | | |
| 10. | Array UBound | |  |
| 11. | Set Array Element Value by Index | | |
| 12. | Array IndexOf and LastIndexOf | |  |
| 13. | Use Array CreateInstance to Create Array | |  |
| 14. | Array Performance Test: One-dimensional array | |  |
| 15. | Free array's memory | | |
| 16. | Array Performance Test: SetValue(i, i) | |  |
| 17. | Declaring, allocating and initializing arrays | |  |
| 18. | Use For Each/Next to find a minimum grade | |  |
| 19. | Reference an Element in an Array by Index | |  |
| 20. | Array Upper Bound and Lower Bound | |  |
| 21. | Init an Array in Declaration | |  |
| 22. | Array Length Property | |  |
| 23. | Declare an Array and reference its member | |  |
| 24. | Store your won Class in an Array | |  |
| 25. | Array Class provides methods for creating, manipulating, searching, and sorting arrays | | |
| 26. | Copies the last two elements from the Object array to the integer array | | |
| 27. | Creates and initializes a new three-dimensional Array of type Int32. | | |
| 28. | Sets a range of elements in the Array to zero, to false, or to Nothing, depending on the element type. | | |
| 29. | Creates a shallow copy of the Array. | | |
| 30. | Converts an array of one type to an array of another type. | | |
| 31. | Copies a range of elements from an Array to another Array | | |
| 32. | Copies all the elements from one Array to another Array | | |
| 33. | Performs the specified action on each element of the specified array. | | |
| 34. | Returns an IEnumerator for the Array. | | |
| 35. | Reverses the sequence of the elements in the entire one-dimensional Array. | | |
| 36. | Array.GetLength | | |
| 37. | Gets the lower bound of the specified dimension in the Array. | | |
| 38. | Uses GetLowerBound and GetUpperBound in the for loop | | |
| 39. | Gets value at the specified position in the one-dimensional Array | | |
| 40. | Reverses the elements in a range | | |