C#| Clone()方法

在C#中,Clone()是一个字符串方法。它用于克隆字符串对象,该对象返回该数据的另一个副本。 换句话说,它返回对这个字符串实例的引用。返回值将只是相同数据的另一个视图。直接在当前字符串实例上调用克隆方法。此方法不接受任何参数。

null

语法:

public object Clone()

返回值类型: 系统对象,或者我们可以说这个字符串实例。

下面的程序演示了Clone()方法的使用:

// C# program to illustrate
// Clone() method
using System;
class Geeks {
// Main Method
public static void Main( string [] args)
{
string s1 = "GeeksForgeeks" ;
// Cannot implicitly convert
// type object to the string.
// So explicit conversion
// using Clone() method
string s2 = (String)s1.Clone();
// Displaying both the string
Console.WriteLine( "String : {0}" , s1);
Console.WriteLine( "Clone String : {0}" , s2);
}
}


输出:

String : GeeksForgeeks
Clone String : GeeksForgeeks

参考: https://msdn.microsoft.com/en-us/library/system.string.clone

© 版权声明
THE END
喜欢就支持一下吧
点赞15 分享