用C#克隆
如果要克隆数组,则在C#中进行克隆很有用。Clone()C#中的方法用于创建数组的相似副本。C#具有Clone方法和ICloneable接口。
我们来看一个使用Clone()方法克隆数组的示例-
示例
using System;
class Program {
static void Main() {
string[] arr = { "one", "two", "three", "four", "five" };
string[] arrCloned = arr.Clone() as string[];
Console.WriteLine(string.Join(",", arr));
Console.WriteLine(string.Join(",", arrCloned));
Console.WriteLine();
}
}输出结果
one,two,three,four,five one,two,three,four,five
上面,我们有一个字符串数组-
string[] arr = { "one", "two", "three", "four", "five" };这样,在一个新的字符串数组中,我们使用了Clone()带有“as”运算符的方法来复制数组-
string[] arrCloned = arr.Clone() as string[];
热门推荐
2 十月简短祝福语
10 庆双节祝福语简短
11 低调祝福语简短10字
12 新年祝福语简短给孩子
13 钱包祝福语简短10字
14 上班收到花束祝福语简短
15 拜年啦祝福语大全简短
16 公司五一祝福语简短最新
17 拜年祝福语 简短句子
18 传统新婚祝福语创意简短