Jon*_*eet 29
Array.Clone并只是转换结果.Array.Copy或Array.CopyTo例如:
using System;
class Test
{
static void Main(string[] args)
{
// Clone the whole array
string[] args2 = (string[]) args.Clone();
// Copy the five elements with indexes 2-6
// from args into args3, stating from
// index 2 of args3.
string[] args3 = new string[5];
Array.Copy(args, 2, args3, 0, 5);
// Copy whole of args into args4, starting from
// index 2 (of args4)
string[] args4 = new string[args.Length+2];
args.CopyTo(args4, 2);
}
}
Run Code Online (Sandbox Code Playgroud)
假设我们从args = { "a", "b", "c", "d", "e", "f", "g", "h" }结果开始:
args2 = { "a", "b", "c", "d", "e", "f", "g", "h" }
args3 = { "c", "d", "e", "f", "g" }
args4 = { null, null, "a", "b", "c", "d", "e", "f", "g", "h" }
Run Code Online (Sandbox Code Playgroud)
sha*_*oth 22
为目标数组分配空间,使用Array.CopyTo():
targetArray = new string[sourceArray.Length];
sourceArray.CopyTo( targetArray, 0 );
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
59860 次 |
| 最近记录: |