C#中的Clone()方法
Clone()C#中的方法用于创建数组的相似副本。
我们来看一个使用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[];
热门推荐
10 新年门口花束祝福语简短
11 盘锦结婚祝福语大全简短
12 父母生日祝福语 简短独特
13 家庭恩爱祝福语简短英文
14 高考俄语祝福语大全简短
15 虎年祝福语 诗句唯美简短
16 生日婚礼祝福语简短精辟
17 虎年喝酒拜年祝福语简短
18 教师闺蜜祝福语简短