日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Array.Copy 方法 总结

發布時間:2025/6/15 编程问答 38 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Array.Copy 方法 总结 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

1,從第一個元素開始復制 Array 中的一系列元素,將它們粘貼到另一 Array 中(從第一個元素開始)。長度指定為 32 位整數。

Visual Basic(聲明)
PublicSharedSubCopy( _sourceArrayAsArray , _destinationArrayAsArray , _lengthAsInteger_ )
Visual Basic(用法)
DimsourceArrayAsArrayDimdestinationArrayAsArrayDimlengthAsIntegerArray .Copy (sourceArray , destinationArray , _length )
publicstaticvoidCopy (
ArraysourceArray ,
ArraydestinationArray ,
intlength
)

參數

sourceArray
類型:System. Array

Array ,它包含要復制的數據。

destinationArray
類型:System. Array

Array ,它接收數據。

length
類型:System. Int32

一個 32 位整數,它表示要復制的元素數目

2,從第一個元素開始復制 Array中的一系列元素,將它們粘貼到另一 Array中(從第一個元素開始)。長度指定為 64 位整數。
publicstaticvoidCopy (
ArraysourceArray ,
ArraydestinationArray ,
longlength
)

參數

sourceArray
類型:System. Array

Array ,它包含要復制的數據。

destinationArray
類型:System. . Array

Array ,它接收數據。

length
類型:System. Int64

一個 64 位整數,它表示要復制的元素數目。該整數必須介于零和 Int32. MaxValue 之間(包括零和 Int32. MaxValue )。

3,從指定的源索引開始,復制 Array中的一系列元素,將它們粘貼到另一 Array中(從指定的目標索引開始)。長度和索引指定為 32 位整數。
publicstaticvoidCopy (
ArraysourceArray ,
intsourceIndex ,
ArraydestinationArray ,
intdestinationIndex ,
intlength
)

參數

sourceArray
類型:System. Array

Array ,它包含要復制的數據。

sourceIndex
類型:System. Int32

一個 32 位整數,它表示 sourceArray 中復制開始處的索引。

destinationArray
類型:System . Array

Array ,它接收數據。

destinationIndex
類型:System. Int32

一個 32 位整數,它表示 destinationArray 中存儲開始處的索引。

length
類型:System. . :: . Int32

一個 32 位整數,它表示要復制的元素數目。

?

4,從指定的源索引開始,復制 Array中的一系列元素,將它們粘貼到另一 Array中(從指定的目標索引開始)。長度和索引指定為 64 位整數。
publicstaticvoidCopy (
ArraysourceArray ,
longsourceIndex ,
ArraydestinationArray ,
longdestinationIndex ,
longlength
)

參數

sourceArray
類型:System. Array

Array ,它包含要復制的數據。

sourceIndex
類型:System. Int64

一個 64 位整數,它表示 sourceArray 中復制開始處的索引。

destinationArray
類型:System. Array

Array ,它接收數據。

destinationIndex
類型:System. Int64

一個 64 位整數,它表示 destinationArray 中存儲開始處的索引。

length
類型:System. Int64

一個 64 位整數,它表示要復制的元素數目。該整數必須介于零和 Int32. . MaxValue 之間(包括零和 Int32. MaxValue )。

?

5,下面的代碼示例說明如何從一個 Object 類型的 Array 復制到 integer 類型的另一個 Array 。

usingSystem;
publicclassSamplesArray {

publicstaticvoidMain() {

// Creates and initializes a new Array of type Int32.
Array myIntArray=Array.CreateInstance( typeof (System.Int32), 5 );
for( int i = myIntArray.GetLowerBound(0); i <= myIntArray.GetUpperBound(0); i++ )
myIntArray.SetValue( i+1, i );

// Creates and initializes a new Array of type Object.
Array myObjArray = Array.CreateInstance( typeof (System.Object), 5 );
for( int i = myObjArray.GetLowerBound(0); i <= myObjArray.GetUpperBound(0); i++ )
myObjArray.SetValue( i+26, i );

// Displays the initial values of both arrays.
Console.WriteLine( "Int32 array:");
PrintValues( myIntArray );
Console.WriteLine( "Object array:");
PrintValues( myObjArray );

// Copies the first element from the Int32 array to the Object array.
Array.Copy( myIntArray, myIntArray.GetLowerBound(0), myObjArray, myObjArray.GetLowerBound(0), 1 );

// Copies the last two elements from the Object array to the Int32 array.
Array.Copy( myObjArray, myObjArray.GetUpperBound(0) - 1, myIntArray, myIntArray.GetUpperBound(0) - 1, 2 );

// Displays the values of the modified arrays.
Console.WriteLine( "Int32 array - Last two elements should now be the same as Object array:");
PrintValues( myIntArray );
Console.WriteLine( "Object array - First element should now be the same as Int32 array:");
PrintValues( myObjArray );
}


publicstaticvoidPrintValues( Array myArr ) {
System.Collections.IEnumerator myEnumerator = myArr.GetEnumerator();
int i = 0;
int cols = myArr.GetLength( myArr.Rank - 1 );
while( myEnumerator.MoveNext() ) {
if( i < cols ) {
i++;
} else{
Console.WriteLine();
i = 1;
}
Console.Write( "/t{0}" , myEnumerator.Current );
}
Console.WriteLine();
}
}
/*
This code produces the following output.

Int32 array:
1 2 3 4 5
Object array:
26 27 28 29 30
Int32 array - Last two elements should now be the same as Object array:
1 2 3 29 30
Object array - First element should now be the same as Int32 array:
1 27 28 29 30
*/


總結

以上是生活随笔為你收集整理的Array.Copy 方法 总结的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。