All pastes #2122487 Raw Edit

example.cs

public text v1 · immutable
#2122487 ·published 2012-02-28 18:18 UTC
rendered paste body
class Program {
	static void Main()
	{
		object  x = new StringBuilder("Hello");
		
		var w = new Wrapper(x);
		
		var fld = typeof(Wrapper).GetField("Wrapped");
		var v = (StringBuilder)fld.GetValue(w);
		
		// Modify object returned by FieldInfo.GetValue().
		v.Append(" World!");
		
		// Write out original value. It should have been modified by the above line.
		Console.WriteLine(x);
		
		// Oh  look, these two variables point to the same object.
		Console.WriteLine(Object.ReferenceEquals(x, v));
	}

	class Wrapper
	{
		public Wrapper(object wrapped)
		{
			this.Wrapped = wrapped;
		}
		
		public object Wrapped;
	}
}