I have some class with private member _stuffs which is of type IStuffs an interface.
When I set a break point just before getting out of the constructor, when debugging and watching the variable at the break point, local variable _stuffs is not null (filled with MyStuffs Object) whereas this._stuffs is null and when back in caller instance MyModelApp._stuffs stays null. Why it is not set with MyStuffs Object ?
public class MyModelApp : ModelApp, IModelApp
{
private App _parent;
private IStuffs _stuffs;
public MyModelApp(object parent)
: base(parent)
{
IStuffs _stuffs = new MyStuffs(this);
// Break point here
}
}
Look carefully at your constructor:
public MyModelApp(object parent)
: base(parent)
{
IStuffs _stuffs = new MyStuffs(this);
}
You're declaring a local variable called _stuffs
and giving it a value. That is not the same as the field _stuffs
. I strongly suspect that you don't want a local variable - you just want to initialize the field instead:
public MyModelApp(object parent)
: base(parent)
{
_stuffs = new MyStuffs(this);
}
See more on this question at Stackoverflow