(related to http://stackoverflow.com/questions/3049477/propertyinfo-setvalue-and-nulls)
If I have public class Thing { public int X; }
, a Thing o
, and a FieldInfo fi
that points to the X
field, why is it legal to call fi.SetValue(o, null)
? The runtime sets the field X
to zero, i.e. default(int)
instead of complaining that a ValueType
cannot be set to null
.
Does anyone know the design choice behind this behavior, which at least from C# violates my principle of least astonishment?