what is the use of clone method and also its types?
what is use of clone method and its types
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
VulpesPosted Feb 8, 2013, 6:08 AM
Jignesh TrivediPosted Feb 8, 2013, 1:37 AM
Hi,
Clone() in C# is implemented by ICloneable interface.
The resulting clone must be of the same type as or a compatible type to the original instance.
with the help of Clone you can create a new object of the same type as the one you invoke it on, without knowing the exact type of the object you are invoking it on.
hope this will help you.
Satyapriya NayakPosted Feb 7, 2013, 11:38 PM
using System;
using System.Windows.Forms;
namespace WindowsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
{
string str = "Clone() Test";
string clonedString = null;
clonedString = (String)str.Clone();
MessageBox.Show (clonedString);
}
}
}
}
Please refer the below links
http://csharp.net-informations.com/string/csharp-string-clone.htm
http://www.codeproject.com/Articles/3441/Base-class-for-cloning-an-object-in-C
Thanks