Clone is a way of shallow copy. string is a reference type. why s2's change can't affect s1?
private void button3_Click(object sender, EventArgs e)
{
string[] s1 = { "a", "b" };
string[] s2 = new string[2];
s2 = (string[])s1.Clone();
//s2=s1; //when Direct assignment s1 changed too
s2[1] = "e";
foreach (var s in s1)
{
this.richTextBox1.Text += s+",";
}
this.richTextBox1.Text += System.Environment.NewLine;
foreach (var s in s2)
{
this.richTextBox1.Text += s + ",";
}
}
}
outputs: a,b, a,e, when shallow copy,it should be :a,e, a,e