如何在 C# 中使用 array 类的 Copy(, ,) 方法
正如其名,C# 中的 Array.Copy() 方法用于将一个数组的元素复制到另一个数组。
以下是语法。
Array.Copy(src, dest, length);
其中
src = 要复制的数组
dest = 目标数组
length = 要复制的元素个数
以下是显示使用 C# 中 array 类的 Copy(,,) 方法的示例。
示例
using System;
class Program {
static void Main() {
int[] arrSource = new int[4];
arrSource[0] = 99;
arrSource[1] = 66;
arrSource[2] = 111;
arrSource[3] = 33;
int[] arrTarget = new int[4];
Array.Copy(arrSource, arrTarget, 4);
Console.WriteLine("Destination Array ...");
foreach (int value in arrTarget) {
Console.WriteLine(value);
}
}
}输出
Destination Array ... 99 66 111 33
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
安卓
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP