ConstrainedCopy() 方法用於將一個數組的元素複製到另一個數組。
用法:
Sub ConstrainedCopy (ByVal source_arr() as object, ByVal index1 as integer, ByVal dest_arr() as object, ByVal index2 as integer, Byval length as integer)
參數:
- Source_arr:它是指定的源數組。
- Index1:源數組的指定索引。
- Dest_arr:它是指定的目標數組。
- Index2:指定目標數組的索引。
- Length:它指定要複製多少個元素。
返回值:它不返回任何值。
程序/源代碼:
下麵給出了演示 Array 類的 ConstrainedCopy() 方法的源代碼。給定的程序已成功編譯並執行。
'VB.NET program to demonstrate the ConstrainedCopy()
'method of Array class.
Imports System
Module Module1
Sub Main()
Dim arr1() As Integer = {10, 20, 30, 40, 50}
Dim arr2() As Integer = {60, 70, 80, 90, 100}
'Copy 3 elements of arr1 element to arr2 from index 0.
Array.ConstrainedCopy(arr1, 2, arr2, 0, 3)
Console.WriteLine("Arr2 Array elements:")
For i = 0 To arr2.Length - 1 Step 1
Console.Write(arr2(i) & " ")
Next
Console.WriteLine()
End Sub
End Module
輸出:
Arr2 Array elements: 30 40 50 90 100 Press any key to continue . . .
說明:
在上麵的程序中,我們創建了一個包含 Main() 函數的模塊 Module1。 Main() 函數是程序的入口點。
在 Main() 函數中,我們創建了兩個數組 arr1 和 arr2。然後我們使用 Array 類的 ConstrainedCopy() 方法將一個整數數組的元素複製到另一個整數數組,這裏我們還指定了長度來指定將複製到目標數組的元素數量。
相關用法
- VB.NET Array Copy()用法及代碼示例
- VB.NET Array Clear()用法及代碼示例
- VB.NET Array Reverse()用法及代碼示例
- VB.NET Array Resize()用法及代碼示例
- VB.NET Array LastIndexOf()用法及代碼示例
- VB.NET Array BinarySearch()用法及代碼示例
- VB.NET Array IndexOf()用法及代碼示例
- VB.NET Array Sort()用法及代碼示例
- VB.NET Array ReferenceEquals()用法及代碼示例
- VB.NET Asc()用法及代碼示例
- VB.NET LTrim()用法及代碼示例
- VB.NET DateTime FromBinary()用法及代碼示例
- VB.NET CLng()用法及代碼示例
- VB.NET RTrim()用法及代碼示例
- VB.NET GetChar()用法及代碼示例
- VB.NET DateTime ToBinary()用法及代碼示例
- VB.NET CInt()用法及代碼示例
- VB.NET CULng()用法及代碼示例
- VB.NET CDbl()用法及代碼示例
- VB.NET LCase()用法及代碼示例
注:本文由純淨天空篩選整理自 VB.Net program to demonstrate the ConstrainedCopy() method of Array class。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。