Why does the original string remain unchanged in example 1 and the original instance not get nulled in example 2, when the string property of an object instance is changed in example 3?
class A { public string property = "class a"; }
static void Main(string[] args)
{
//Example1
string var = "something";
string[] array = new string[] { var };
array[0] += " again";
// var is unchanged, contents in array slot zero are changed
//Example2
A instance = new A();
object[] array2 = new object[] { instance };
array2[0] = null;
// instance is also unchanged, contents in array slot zero are now null
//Example3
A anotherInstance = new A();
object[] array3 = new object[] { anotherInstance };
(array3[0] as A).property = " else";
// the *propery* of anotherInstance changes as expected
return;
}