If I have a class
class widget {
public int theNum;
public string theName;
}
and I initalise like this
widget wgt = new widget { thename="tom" };
theNum will be zero.
Is there a way for me to examine the instance wgt to determine that the member theNum was defaulted i.e. excluded from the object initialisation?
As long as
theNumis a field you cannot tell if it was left uninitialized or if it was explicitly initialized to its default value (which in this case is0, but could be different if you hadpublic int theNum = 42).If
theNumwere a property then you could set a flag from within the property setter that allowed you to determine if the setter was invoked, no matter what value you set the property to. For example: